element ui 动态表格,根据表格第一个字符,显示不同颜色
效果图
1.在el-table 标签内
<el
-table
: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'
}
}
}
转载请注明原文地址:https://blackberry.8miu.com/read-34559.html