使用 highlight-current-row 属性
el-table 加上 highlight-current-row 属性。
<el-table ref='tTable' :data="dataList" highlight-current-row></el-table>
调用 setCurrentRow(row, true) 设置当前行高亮,row为dataList里面的数据。
selectRow(row) {
if (row) {
this.$refs.tTable.setCurrentRow(row, true);
} else {
this.$refs.tTable.setCurrentRow(); // 取消高亮
}
}
如果要改变默认的高亮的颜色。这样就把项目中所有el-table的高亮颜色都改了。
<style lang="scss">
.el-table__body tr.current-row>td {
background: #453878 !important;
}
</style>
使用 row-class-name
<el-table ref='transcriptTable' :data="sentenceList" height="400" :row-class-name="transcriptTableRowClassName"></table>
transcriptTableRowClassName({row, rowIndex}) {
if (rowIndex === this.curSentenceRowIndex) {
return 'speak-row';
}
return '';
},
如果是当前行时,返回不同的样式。
<style lang="scss">
.el-table .speak-row {
color: darkorange;
font-size: 15px;
font-weight: 500;
background: #f0f9eb;
}
</style>