表格某一列根据值不同,显示不同颜色vue

1.样式图

图一:

图二: 

 2.相关代码

status的值来自字典

<el-table-column
   label="状态"
   align="left"
   prop="status"         
   width="110"
>
   <template slot-scope="scope">           
      //图一样式
      <el-button :type="getType(scope.row)" size="mini">
           {{statusFormat(scope.row)}}
      </el-button>
      //图二样式
      //<span :class="{'warningColor':scope.row.status==0,
      //   'mainColor':scope.row.status==1,
      //   'infoColor':scope.row.status==2,'dangerColor':scope.row.status==3,
      //   'sucessColor':scope.row.status==4}"
      //>
      //  {{statusFormat(scope.row)}}
      //</span>
   </template>  
</el-table-column>
methods: { 
   //图一
   getType(row){
      if(row.status==0){
          return 'warning'
      }else if(row.status==1){
          return 'primary'
      }else if(row.status==2){
          return 'info'
      }else if(row.status==3){
          return 'danger'
      }else if(row.status==4){
          return 'success'
      }
   }
}
<style scoped>
/* 图二 */
.mainColor {
    color: #409EFF;
}
.sucessColor {
    color: #6EC543;
}
.warningColor{
    color: #fda22b;
}
.infoColor{
    color: #cecfc3;
}
.dangerColor{
    color: #EB4040;
}
</style>

  • 1
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值