Vue + ElementUI 动态显示表格某个单元格:值和颜色

方法一:直接在template scope 使用v-if判断
<el-table-column prop="status" label="显示状态">
  <template scope="scope">
    <span v-if="scope.row.status=== 1">在线</span>
    <span v-else-if="scope.row.status=== 0">离线</span>
  </template>
</el-table-column>

 

方法二:element-ui formatter
 
1. el-table-column 绑定formatter属性
<el-table-column 
  prop="status"
  align='center'
  label="显示状态"
  :formatter="formatStatus">
</el-table-column>

 

2. 定义绑定的方法
formatStatus(row, column) {
  return row.status == 'Y' ? '已执行' : '未执行'
},

 

方法三:在data对象中静态绑定属性
 
1. 在data中定义相关值
data () {
  return {
    ASSET_STATUS: {
      'used': { 'status': '使用中', 'type': 'primary' },
      'noused': { 'status': '未使用', 'type': 'info' },
      'broken': { 'status': '故障', 'type': 'danger' },
      'trash': { 'status': '废弃', 'type': 'warning' }
    }
  }
}

 

2. 在template中使用
<el-table-column prop='status' label='状态'>
  <template slot-scope="scope">
    <div slot="reference" class="name-wrapper" style="text-align: center">
      <el-tag :type="ASSET_STATUS[scope.row.status].type">
        {{ASSET_STATUS[scope.row.status].status}}
      </el-tag>
    </div>
  </template>
</el-table-column>

 

!!!!可以使用element ui 的 e-tag标签来显示不同的背景颜色!

 

 

 

 

 

 

转载于:https://my.oschina.net/u/264284/blog/2872831

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值