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

转载自https://blog.csdn.net/ahrl__/article/details/80805792#comments

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

更改表格的样式

使用header-cell-style属性,可为函数或对象
1. 函数写法

<!-- html -->
<el-table :header-cell-style="rowClass"></el-table>
  • 1
  • 2
//在method里面写上方法
rowClass({ row, rowIndex}) {
    console.log(rowIndex) //表头行标号为0
    return 'background:red'
}
  • 1
  • 2
  • 3
  • 4
  • 5
  1. 对象写法
<!-- html -->
<el-table :header-cell-style="{background:'red'}"></el-table>
  • 1
  • 2

更改表格中某个单元格的样式

  1. 函数写法
<!-- html -->
<el-table :cell-style="cellStyle"></el-table>
  • 1
  • 2
//在method里面写上方法
cellStyle({row, column, rowIndex, columnIndex}){
    if(rowIndex === 1 && columnIndex === 2){ //指定坐标
        return 'background:pink'
    }else{
        return ''
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  1. 对象写法
<!-- html -->
<el-table :cell-style="{background:'pink'}"></el-table>
  • 1
  • 2

 修改某列:

cellStyle({row, column, rowIndex, columnIndex}){  
            if(columnIndex === 1){//指定列号  
                return 'background:pink'  
            }else{  
                return ''  
            }  
        }  

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

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值