循环的表格,使用:row-class-name="tableRowClassName"方法,动态绑定方法
<el-table :data="tableData" :row-class-name="tableRowClassName">
<el-table-column v-for="(item,index) in columnList" :label="item" width="140">
<template slot-scope="scope">
<span>{{ scope.row[index] }}</span>
</template>
</el-table-column>
</el-table>
判断rowIndex = 你要改变样式的值,比如我取的是我表格数据最后两条。返回不同的class名称
tableRowClassName({ row, rowIndex }) {
if (rowIndex === this.tableData.length - 1) {
return 'warning-row'
} else if (rowIndex === this.tableData.length - 2) {
return 'success-row'
}
return ''
}
我这里需要穿透一下,要不然值绑定上,但是没有渲染css样式。
/deep/ .el-table .warning-row {
background: #328efe;
color: #FFFFFF;
}
/deep/ .el-table .success-row {
background: #e78200;
color: #FFFFFF;
}