Element table set the header, row, column or specified cell background color

effect:

<template>
  <el-table
    :data="tableData"
    border
     :header-cell-style="rowClass"
     :cell-style="cellStyle" 
    style="width: 100%">
    <el-table-column
      prop="date"
      label="日期"
      width="150">
    </el-table-column>
    <el-table-column
      prop="name"
      label="姓名"
      width="120"
         >
    </el-table-column>
    <el-table-column
      prop="province"
      label="省份"
      width="120">
    </el-table-column>
    <el-table-column
      prop="city"
      label="市区"
      width="120">
    </el-table-column>   
  </el-table>
</template>

methods: {
    //设置表头的颜色
    rowClass({ row, rowIndex}) {
        console.log(rowIndex) //表头行标号为0
        return 'background:red'
      },
    //设置指定行、列、具体单元格颜色
    cellStyle({row, column, rowIndex, columnIndex}){
        if(rowIndex === 1 && columnIndex === 2){ //指定坐标rowIndex :行,columnIndex :列
        return 'background:red' //rgb(105,0,7)
    }else{
        return ''
    }
}
  

 

Guess you like

Origin blog.csdn.net/qq_36802726/article/details/103149495