:cell-style属性
javascript
//html
<el-table
empty-text="暂无数据"
:data="datalist.table"
:max-height="height"
row-key="id"
border
:cell-style="cellStyle"
>
<el-table>
//js
//动态设置单元格颜色
const cellStyle = ({ row, column, rowIndex, columnIndex }) => {
if (column.property == "alarmLevel") {
// console.log(row);
if (row.alarmLevel == 1) {
return { backgroundColor: "rgba(80,227,194,0.4)", color: "#333333" };
} else if (row.alarmLevel == 2) {
return { backgroundColor: "rgba(247,220,111,0.4)", color: "#333333" };
} else if (row.alarmLevel == 3) {
return { backgroundColor: "rgba(234,149,24,0.4)", color: "#333333" };
} else if (row.alarmLevel == 4) {
return { backgroundColor: "rgba(216,30,6,0.4)", color: "#333333" };
}
}
};
上一篇文章,