表格自定义不同状态的样式

当表格中数据很多,我们需要根据不同的状态来区分自定义样式时,可以参考本文。


前言

ElementUI提供了表格的用法,那我们就在表格的基础上进一步完成具体的需求。


一、实现效果

二、实现步骤

1.vue页面

<el-table-column label="状态" align="center">
    <template slot-scope="scope">
      <div
        class="status-bg"
        :class="
          scope.row.status == 1
            ? 'primary'
            : scope.row.status == 2
            ? 'success'
            : 'danger'
        "
        :style="{
          '--bgColor': statusColorList[scope.row.status - 1].color
        }"
      ></div>
      {{ statusColorList[scope.row.status - 1].name }}
    </template>
</el-table-column>

// 数据
statusColorList: [
   { color: '#005BFF', name: '待审核' },
   { color: '#67C23A', name: '已通过' },
   { color: '#FF192C', name: '已拒绝' }
],

2.css样式

.status-bg {
  position: relative;
  display: inline-block;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  &::before {
    position: absolute;
    top: 3px;
    left: 3px;
    width: 6px;
    height: 6px;
    content: '';
    background-color: var(--bgColor);
    border-radius: 50%;
  }
  &.primary {
    background-color: rgba(0, 91, 255, 0.2);
  }
  &.danger {
    background-color: rgba(255, 25, 44, 0.2);
  }
  &.success {
    background-color: rgba(103, 194, 58, 0.2);
  }
}

总结

以上就是今天要讲的内容,动态的设置表格中状态的样式,希望对你有所帮助。

  • 11
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值