element el-table表格表头某一列表头字段修改颜色

需求:

element el-table表格表头某一列表头字段修改颜色_第1张图片

1 使用 :header-cell-class-name="addClass" 属性
element el-table表格表头某一列表头字段修改颜色_第2张图片
2 根据显示条件 在redText,whiteText 中设置你想要添加的必填表头index
element el-table表格表头某一列表头字段修改颜色_第3张图片
3.根据条件修改文字样式
element el-table表格表头某一列表头字段修改颜色_第4张图片

完整代码

<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>
  methods: {
    addClass({ row, rowIndex, column, columnIndex }) {
      if (columnIndex == 2) {
        return "redText";
      } else {
        return 'whiteText'
      }
    },
 }

实现

element el-table表格表头某一列表头字段修改颜色_第5张图片
参考链接:https://blog.csdn.net/weixin_47438917/article/details/127262354

你可能感兴趣的:(vue.js,前端,javascript,elementui,el-table,表头字段颜色修改)