element ui 动态表格,根据表格第一个字符,显示不同颜色
效果图
1.在el-table 标签内
<el-table
// 通过:cell-style
:cell-style="cellStyle"
:default-sort="{prop: 'id', order: 'descending'}"
:header-cell-style="{background:'#ebeffb',color:'#000'}"
:data="dataList"
border
v-loading="dataListLoading"
@selection-change="selectionChangeHandle"
style="width: 100%;">
2.在methods方法里面自己写一个方法
methods: {
cellStyle (row, column, rowIndex, columnIndex) {
// 根据报警级别显示颜色
if (row.column.label === '相比去年总产量' && row.row.lastUtilization.indexOf('+') !== -1) {
return 'color:red'
}
if (row.column.label === '相比去年总产量' && row.row.lastUtilization.indexOf('-') !== -1) {
return 'color:green'
}
if (row.column.label === '相比去年' && row.row.lastYearUtilization.indexOf('+') !== -1) {
return 'color:red'
}
if (row.column.label === '相比去年' && row.row.lastYearUtilization.indexOf('-') !== -1) {
return 'color:green'
}
}
}