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

相关推荐
老前端的功夫3 分钟前
【Java从入门到入土】21:List三剑客:ArrayList、LinkedList、Vector的爱恨情仇
java·javascript·网络·python·list
小李云雾7 分钟前
零基础-从ESS6基础到前后端联通实战
前端·python·okhttp·中间件·eclipse·html·fastapi
SAP小崔说事儿10 分钟前
SAP B1 批量应用用户界面配置模板
java·前端·ui·sap·b1·无锡sap
Amos_Web20 分钟前
Rspack 源码解析 (1) —— 架构总览:从 Node.js 到 Rust 的跨界之旅
前端·rust·node.js
qq_4061761420 分钟前
React 组件传参 & 路由跳转传参
前端·javascript·react.js
电商API&Tina21 分钟前
唯品会数据采集API接口||电商API数据采集
java·javascript·数据库·python·sql·json
Csvn25 分钟前
React 测试入门:Jest + Testing Library 完整指南
前端·react.js
悟空瞎说27 分钟前
Flutter面试九阳神功第六层:Platform Channels/三棵树/Key/动画,大白话+实操代码(2026版)
前端
Oneslide30 分钟前
手写签名组件实现原理
前端
Lufeidata43 分钟前
go语言学习记录-入门阶段
前端·学习·golang