element el-table表格表头某一列表头字段修改颜色

需求:

1 使用 :header-cell-class-name="addClass" 属性

2 根据显示条件 在redText,whiteText 中设置你想要添加的必填表头index

3.根据条件修改文字样式

完整代码

html 复制代码
<el-table ref="tableRef" :cell-style="{ color: '#FFF', background: '#333' }"
      :header-cell-style="{ background: '#333' }" 
      :header-cell-class-name="addClass" 
      row-key="id" 
      :data="tableData"
      style="width: 100%" 
      :default-sort="{ prop: 'barcode.putInDate', order: 'descending' }" 
      @select="select"
      @select-all="selectAll" @sort-change="sortChange" :tree-props="{
        children: 'children',
        hasChildren: 'hasChildren',
      } ">
 </el-table>
javascript 复制代码
  methods: {
    addClass({ row, rowIndex, column, columnIndex }) {
      if (columnIndex == 2) {
        return "redText";
      } else {
        return 'whiteText'
      }
    },
 }
css 复制代码
<style rel="stylesheet/scss" lang="scss" scoped>
::v-deep .el-table__header-wrapper th.redText {
  color: red;
}
::v-deep .el-table__header-wrapper th.whiteText {
  color: #fff;
}
</style>

实现


参考链接https://blog.csdn.net/weixin_47438917/article/details/127262354

相关推荐
还是大剑师兰特27 分钟前
Vue3 前端专属配置(VSCode settings.json + .prettierrc)
前端·vscode·json
前端小趴菜0537 分钟前
vue3项目优化方案
前端·javascript·vue.js
Mr_Swilder38 分钟前
WebGPU 基础 (WebGPU Fundamentals)
前端
张3蜂1 小时前
HTML5语义化标签:现代网页的骨架与灵魂
前端·html·html5
悟空瞎说1 小时前
我用 PixiJS 撸了个圆桌会议选座系统,从 0 到 1 踩坑全复盘
前端
码云之上1 小时前
从 SPA 到全栈:AI 时代的前端架构升级实践
前端·架构·ai编程
Irene19911 小时前
对比总结:Vue3中的 watch 和 Pinia中的 $subscribe
vue.js·pinia·watch·subscribe
小陈同学呦1 小时前
关于如何使用CI/CD做自动化部署
前端·后端
前端Ah1 小时前
记 华为鸿蒙机型小程序使用uni.createInnerAudioContext() 播放音频播放两次的问题
前端
用户221765927922 小时前
css border-left 怎么设置 border 展示为椭圆
前端