用到cell-style方法:
<el-table ref="table" :cell-style="tableRowStyle" :data="tableData" border >
js 注意:与平时表格数据不同,举例数据需要循环
重点!!:foreach失效,需要用for in !!
tableRowStyle({ row, column, rowIndex, columnIndex }) {
if (row.ceshi.length) {
if (columnIndex !== 0) {
console.log(row.ceshi, column, rowIndex, columnIndex, 'val.....')
columnIndex = columnIndex - 1
for (let index = 0; index < row.ceshi.length; index++) {
if (this.postList[columnIndex].value === row.ceshi[index].postId) {
return 'background:#F5F7FA;!important;'
}
}
}
}
},
简单数据举例:
tableRowStyle({ row, column, rowIndex, columnIndex }) {
if (columnIndex == 0) {
return 'background:#F5F7FA;!important;'
},
ht背景色
<style lang='scss'>
.quiry{
.el-table th.el-table__cell{
background-color:rgb(128,100,162);
color: #fff;
}
}
</style>