element-ui table表格修改某列表头样式、背景色等

通过header-cell-style属性可以实现该需求

    <el-table
      v-loading="loading"
      :data="tableData"
      border
      :header-cell-style="headerStyleEvent"     
      row-class-name="tableRowClassName"
    >
    </el-table>

通过索引寻找到对应的列

  methods: {
    headerStyleEvent({ row, column, rowIndex, columnIndex }) {
      if (columnIndex == 7 || columnIndex == 8) {
        return 'background-color:#FFFF99'
      } else if (columnIndex == 9 || columnIndex == 10) {
        return 'background-color:#169BD5'
      } else if (columnIndex == 11 || columnIndex == 12 || columnIndex == 13) {
        return 'background-color:#669999'
      } else if (
        columnIndex == 14 ||
        columnIndex == 15 ||
        columnIndex == 16 ||
        columnIndex == 17
      ) {
        return 'background-color:#FF9900'
      }
    }
    }

效果如图所示
在这里插入图片描述

posted @ 2022-06-06 18:36  梓言  阅读(2553)  评论(0)    收藏  举报