element-ui el-table 定義每個單元格的顏色
阿新 • • 發佈:2022-03-26
<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 '' } }