element-ui 一整行变色/某个单元格变色

* row 表格每一行的数据
* column 表格每一列的数据
* rowIndex 表格的行索引,不包括表头,从0开始
* columnIndex 表格的列索引,从0开始
公共的template中:

      
      
      
      
      
      
 

让表格的某个单元格变色

methods中:
    isRed ({row, column, rowIndex, columnIndex}) {
      if (columnIndex === 2) {
        return {
          backgroundColor: 'red'
        }
      }
    },

让选择到的那行表格变色

template中:
:row-style="isRed"

data中:
selectionIndex: []  // 把选择到的表格下标存到数组中
selectionId: []     // 把选择到的当前行的id存到数组中

methods中:
selected (select) {
  this.batchCancelId = []
  this.selectionIndex = []
  select.map((item) => {
    this.selectionId.push(item.id)
    this.selectionIndex.push(item.index)
  })
},
isRed({row, rowIndex}) {
  if (this.selectionIndex.includes(rowIndex)) {
     return {
        backgroundColor: 'red', 
        borderLeft: '2px solid #003791'
     }
  }
}

 

cell-class-name 和 cell-style 的区别

cell-class-name cell-style

行的 className 的回调方法

也可以使用字符串为所有行设置一个固定的 className。

行的 style 的回调方法

也可以使用一个固定的 Object 为所有行设置一样的 Style。

Function({row, rowIndex})/String  Function({row, rowIndex})/Object

row-class-name 和 row-style 的区别

cell-class-name cell-style
单元格的 className 的回调方法,也可以使用字符串为所有单元格设置一个固定的 className 单元格的 style 的回调方法,也可以使用一个固定的 Object 为所有单元格设置一样的 Style。
Function({row, column, rowIndex, columnIndex})/String Function({row, column, rowIndex, columnIndex})/Object

你可能感兴趣的:(vue,element-ui)