![v2-0b316161f443976a626bb43d706e1931_1440w.jpg?source=172ae18b](http://img-01.proxy.5ce.com/view/image?&type=2&guid=acc51022-532e-eb11-8da9-e4434bdf6706&url=https://pic1.zhimg.com/v2-0b316161f443976a626bb43d706e1931_1440w.jpg?source=172ae18b)
element更改表格表头、行、指定单元格样式
在学习vue过程中,总结了一下使用element时更改表格样式的方式。
更改表格的样式
使用header-cell-style属性,可为函数或对象
1. 函数写法
<!-- html -->
<el-table :header-cell-style="rowClass"></el-table>
2//在method里面写上方法
rowClass({ row, rowIndex}) {
console.log(rowIndex) //表头行标号为0
return 'background:red'
}
对象写法
<!-- html -->
<el-table :header-cell-style="{background:'red'}"></el-table>
更改表格中某个单元格的样式
函数写法
<!-- html -->
<el-table :cell-style="cellStyle"></el-table>
//在method里面写上方法
cellStyle({row, column, rowIndex, columnIndex}){
if(rowIndex === 1 && columnIndex === 2){ //指定坐标
return 'background:pink'
}else{
return ''
}
}
对象写法
<!-- html -->
<el-table :cell-style="{background:'pink'}"></el-table>