vue表格根据不同的数据设置不同样式

1、根据数据不同给行或单元格赋不同的class,主要使用如下回调函数

如单号行设为red_row,双号行设为yellow_row,代码如下:

tableRowClassName({
        row,
        rowIndex
      }) {
    if (rowIndex % 2 === 1) {
        return 'yellow_row';
    }
    return 'red_row';
}

2、为不同的class设置不同的样式。

<style>
  .el-table .el-table__body tbody .red-row {
    background: #f56c6c;
  }

  .el-table .el-table__body tbody .yellow-row {
    background: #daf56c;
  }
</style>
发布了8 篇原创文章 · 获赞 0 · 访问量 360

猜你喜欢

转载自blog.csdn.net/weixin_40356468/article/details/102817524