自学内容网 自学内容网

el-table中根据状态改单元格样式

需求:el-table中,有一列需要根据状态不同,显示的样式也不通。

解决方法: :cell-style="cellStyle"

   <el-table
        :data="tableData"
        style="width: 100%"
        size="mini"
        border
        :header-cell-style="{ textAlign: 'center', color: '#606266' }"
        :cell-style="cellStyle"
      >

   <el-table-column prop="result" label="检测结果"></el-table-column>
  </el-table>

    // 当监测结果为 已携带 的状态,加上背景色,字体颜色
    cellStyle({ row, column, rowIndex, columnIndex }) {
      if (row.result == '携带' && column.label == '检测结果') {
        return 'background:#d9001b;textAlign: center;color:#fff;'
      } else {
        return 'textAlign: center'
      }
    },


原文地址:https://blog.csdn.net/weixin_69670563/article/details/142525868

免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!