需求:根据后端返回的颜色值渲染table中来源这一列的背景颜色
实现效果:
这里用到的是:cell-style属性
代码:
<el-table
ref="table"
:header-cell-style="{ color: '#FFF', background: '#333' }"
:data="queueTaskList"
style="width: 100%; color: #ffffff"
:cell-style="tableCellStyle"
>
// 改变某一列单元格背景颜色
tableCellStyle({ row, column, rowIndex, columnIndex }) {
console.log(row.taskColor, "-->row.taskColor");
let rowBackground = {};
if (row.taskColor) {
if (columnIndex === 2) {
rowBackground.background = row.taskColor;
} else {
rowBackground.background = "#333";
}
} else {
rowBackground.background = "#333";
}
return rowBackground;
},