el-table动态改变行颜色【vue】
``
1.<el-table>标签中加属性:row-class-name="tableRowClassName"
<el-table :key="tableKey" ref="table" v-loading="loading" :data="tableData.records" border fit
:row-class-name="tableRowClassName"
row-key="id" @filter-change="filterChange" @selection-change="onSelectChange" @sort-change="sortChange"
@cell-click="cellClick">
<el-table-column align="center" type="selection" width="40px" column-key="selectionId" :reserve-selection="true"/>
<el-table-column label="id" align="center" prop="id" sortable="custom"/>
<el-table-column label="常用语" align="center" prop="commonWords"/>
<el-table-column label="创建日期" align="center" prop="createTime"/>
<el-table-column label="更新日期" align="center" prop="updateTime"/>
<el-table-column label="操作" column-key="operation" align="center" class-name="small-padding fixed-width"
fixed="right" width="150px">
<template slot-scope="{row}">
<i class="el-icon-edit table-operation" style="color: #2db7f5;" v-if="row.commonState==null" @click="editRow(row)"/>
<i class="el-icon-delete table-operation" style="color: #f50;" v-if="row.commonState==null" @click="del(row)"/>
</template>
</el-table-column>
</el-table>
2. methods: {}中添加方法tableRowClassName
tableRowClassName({row}) {
if(row.commonState === true) {
return 'common-row';
}
},
3. 添加css样式
<style>
.el-table .common-row {
background: pink!important;
}
</style>