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 分钟前
Vue 中directive的钩子函数 作用,调用时机,参数,及使用场景举例说明
前端·javascript·vue.js·指令·directive
梵得儿SHI1 分钟前
Vue 3 生态工具实战:UI 组件库与表单验证完全指南
前端·ui·vue3·elementplus·表单验证·antdesignvue·veevalidate
成都渲染101云渲染66662 分钟前
UE5云渲染选它:5090显卡加持,高负载不崩
前端
●VON8 分钟前
Flutter Web 开发:解决跨域(CORS)问题的终极指南
前端·flutter
一只大马猴呀20 分钟前
Windows 安装使用 nvm,Node.js、npm多版本管理、切换
前端·npm·node.js
吴声子夜歌22 分钟前
TypeScript——VSCode搭建开发环境
javascript·vscode·typescript
网络点点滴23 分钟前
渐层响应式shallowRef和shallowReactive
前端·javascript·vue.js
@yanyu66625 分钟前
05计算属性与定时器
前端·javascript·vue.js
哈__28 分钟前
ReactNative项目OpenHarmony三方库集成实战:react-native-chart-kit
javascript·react native·react.js
小同志0030 分钟前
JQuery
前端·javascript·jquery