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

相关推荐
Kx…………18 分钟前
Day2-2:前端项目uniapp壁纸实战
前端·学习·uni-app·html·实战·项目
申小兮21 分钟前
Vue Router(二)
前端·vue.js·vue-router
代码小学僧22 分钟前
如何优雅地重构一个企业官网 Nextjs 前端项目
前端·react.js·前端工程化
零零壹1123 分钟前
Swagger 中的 x-nullable 是什么意思?
前端·后端·面试
三小河25 分钟前
自定义VITE插件,生成可修改配置项,用于不同项目部署
前端·javascript·react.js
樊小肆29 分钟前
手把手教你!0 基础搭建 H5 AI 对话页面:渲染信息全攻略-基础版
前端·vue.js
前端_xiaolu29 分钟前
前端知识库【合集】
前端
IcecreamH2o31 分钟前
利用AI编写一个chrome扩展程序——同步不同环境的LocalStorage
前端·浏览器
wordbaby33 分钟前
前端组件解耦利器:发布订阅模式
前端
yaoganjili39 分钟前
什么!你还在使用Tailwind CSS,老厂长推荐 Open Props
前端