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 分钟前
身份证照片自动裁剪(OpenCV 四边形检测 + 透视矫正)
前端·后端
跟着珅聪学java1 分钟前
Electron + Vue 现代化“新品展示“和“快捷下单“菜单
开发语言·前端·javascript
何贤2 分钟前
用 Three.js 写了一个《我的世界》,结果老外差点给我众筹做游戏?
前端·开源·three.js
C_心欲无痕14 分钟前
使用 XLSX.js 导出 Excel 文件
开发语言·javascript·excel
踩着两条虫19 分钟前
AI 驱动的 Vue3 应用开发平台 深入探究(七):双向代码转换之 Vue源码到DSL解析
前端·vue.js·ai编程
专业流量卡20 分钟前
用ai去看源码
前端·react.js
踩着两条虫22 分钟前
AI 驱动的 Vue3 应用开发平台 深入探究(六):双向代码转换之DSL到Vue代码生成
前端·vue.js·ai编程
前端老兵AI22 分钟前
React vs Vue 2026年怎么选?9年前端的真实建议
vue.js·react.js
Wect22 分钟前
React 中的双缓存 Fiber 树机制
前端·react.js·面试
天才熊猫君23 分钟前
Vue 3 中 Watch 的陷阱:为什么异步操作后创建的监听会泄漏?
前端·javascript