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

相关推荐
Mintopia几秒前
Vite 发展现状与回顾:从“极致开发体验”到生态基础设施
前端
前端双越老师24 分钟前
前端面试常见的 10 个场景题
前端·面试·求职
孟祥_成都1 小时前
【全网最通俗!新手到AI全栈开发必读】 AI 是如何进化到大模型的
前端·人工智能·全栈
牛奶2 小时前
AI辅助开发的基础概念
前端·人工智能·ai编程
摸鱼的春哥2 小时前
Agent教程15:认识LangChain,Agent框架的王(上)
前端·javascript·后端
明月_清风3 小时前
自定义右键菜单:在项目里实现“选中文字即刻生成新提示”
前端·javascript
明月_清风3 小时前
告别后端转换:高质量批量导出实战
前端·javascript
刘发财7 小时前
弃用html2pdf.js,这个html转pdf方案能力是它的几十倍
前端·javascript·github
牛奶10 小时前
2026年大模型怎么选?前端人实用对比
前端·人工智能·ai编程
牛奶10 小时前
前端人为什么要学AI?
前端·人工智能·ai编程