element-ui的el-table改变单个单元格的背景颜色

效果图如下:

  • 需要在el-table 标签中添加 :cell-style=" " 方法

  • 代码如下(页面结构)

  • 代码如下(方法处理)

    methods: {
      // 背景颜色处理
      tableCellStyle ({row, column, rowIndex, columnIndex}) {
        if(columnIndex === 11) {      // 表格的第11行做处理
          if(fxdj == 4) {             // 如果是低风险背景色蓝色,字体色白色
          return 'background:blue; color:white' 
          }else if(fxdj == 2) {       // 较大风险
            return 'background:orange' 
          }else if(fxdj == 1) {       // 重大风险
            return 'background:red'
          } else {                    // 一般风险
            return 'background:yellow'
          }
        }else {
          return ''
        }
      },
    }

 

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐