代码片段:
<el-table
v-loading="dataListLoading"
:data="dataList"
border
@selection-change="dataListSelectionChangeHandle"
style="width: 100%;"
:max-height="tableHeight"
@row-click="rowClick"
:row-class-name="rowClassName"
:row-style="rowStyle"
:stripe="false"
>
主要代码
@row-click="rowClick"
:row-class-name="rowClassName"
:row-style="rowStyle"
:stripe="false"
stripe :
方法实现:
// 当前点击行index
rowClick (row) {
this.rowIndex = row.index
},
// 把每行的 index 放入 row 中
rowClassName ({ row, rowIndex }) {
row.index = rowIndex
},
// 如果当前行index 是点击行,就改变颜色
rowStyle ({ row, rowIndex }) {
if (this.rowIndex === rowIndex) {
return {
'background-color': '#ffeecf !important'
}
}
}
注意:
stripe 为 false,取消当前表格的斑马纹。点击才有变色效果。