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

相关推荐
南山安1 小时前
从反转字符串看透面试官的“内心戏”:你的算法思维到底怎么样?
javascript·算法·面试
东华帝君1 小时前
vue3自定义v-model
前端
www_stdio1 小时前
用 localStorage 打造本地待办清单:一个轻量级的前端实践
javascript·css·json
JIngJaneIL1 小时前
远程在线诊疗|在线诊疗|基于java和小程序的在线诊疗系统小程序设计与实现(源码+数据库+文档)
java·数据库·vue.js·spring boot·小程序·毕设·在线诊疗小程序
fruge1 小时前
搭建个人博客 / 简历网站:从设计到部署的全流程(含响应式适配)
前端
光影少年1 小时前
css影响性能及优化方案都有哪些
前端·css
呆呆敲代码的小Y2 小时前
2025年多家海外代理IP实战案例横向测评,挑选适合自己的
前端·产品
q***3752 小时前
爬虫学习 01 Web Scraper的使用
前端·爬虫·学习
v***5652 小时前
Spring Cloud Gateway
android·前端·后端
b***59432 小时前
分布式WEB应用中会话管理的变迁之路
前端·分布式