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

相关推荐
工边页字2 分钟前
AI 开发必懂:Context Window(上下文窗口)到底是什么?
前端·人工智能·后端
Mr_Swilder4 分钟前
intel显卡本地部署大模型
前端
yuki_uix4 分钟前
Promise 与 async/await:从回调地狱到优雅异步的演进之路
前端·javascript
over6977 分钟前
📸《拍照记单词》—— 从零到上线的完整开发指南(超详细版)
前端·人工智能·产品
毛骗导演8 分钟前
万字解析 OpenClaw 源码架构-架构概览
前端·架构
天才熊猫君16 分钟前
Flex布局深度解析:为什么我的Flex项目不按预期收缩?
前端
风雪心17 分钟前
Antd组件库Form的onValuesChange和getFieldsValue的调用时机分析
前端
Moment17 分钟前
2026 趋势预测:Vibe Coding 之后,人人都会拥有专属 Agent 吗?
前端·javascript·后端
前端Hardy33 分钟前
Bun 1.0 正式发布:JavaScript 运行时的新王者?启动快 5 倍,打包小 90%!
前端·javascript·面试
Bigger44 分钟前
从 Grunt 到 Vite:前端构建工具十几年的演化
前端·vite·前端工程化