转载自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官网的属性想结合,就可以达到想要的效果。

GitHub 加速计划 / eleme / element
15
2
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:2 个月前 )
c345bb45 1 年前
a07f3a59 * Update transition.md * Update table.md * Update transition.md * Update table.md * Update transition.md * Update table.md * Update table.md * Update transition.md * Update popover.md 1 年前
Logo

AtomGit 是由开放原子开源基金会联合 CSDN 等生态伙伴共同推出的新一代开源与人工智能协作平台。平台坚持“开放、中立、公益”的理念,把代码托管、模型共享、数据集托管、智能体开发体验和算力服务整合在一起,为开发者提供从开发、训练到部署的一站式体验。

更多推荐