element更改表格表头、行、指定单元格样式

在学习vue过程中,总结了一下使用element时更改表格样式的方式。

<!--more -->

更改表格的样式

使用header-cell-style属性,可为函数或对象<br>

  1. 函数写法

1
2
<!-- html -->
<el-table :header-cell-style="rowClass"></el-table>

1
2
3
4
5
//在method里面写上方法
rowClass({ row, rowIndex}) {
console.log(rowIndex) //表头行标号为0
return 'background:red'
}

  1. 对象写法

1
2
<!-- html -->
<el-table :header-cell-style="{background:'red'}"></el-table>

  1. 函数写法

1
2
<!-- html -->
<el-table :header-cell-style="cellStyle"></el-table>

1
2
3
4
5
6
7
8
//在method里面写上方法
cellStyle({row, column, rowIndex, columnIndex}){
if(rowIndex === 1 && columnIndex === 2){ //指定坐标
return 'background:pink'
}else{
return ''
}
}

  1. 对象写法

1
2
<!-- html -->
<el-table :cell-style="{background:'pink'}"></el-table>

其他设置跟上面的写法基本相同,跟element官网的属性想结合,就可以达到想要的效果。

本文标题:element更改表格表头、行、指定单元格样式

文章作者:AHRL

发布时间:2018年06月25日 - 16:06

最后更新:2018年06月25日 - 18:06

原始链接:http://ahrler.xyz/2018/06/25/element更改表格表头、行、指定单元格样式/

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

-------------本文结束感谢您的阅读-------------