el-table 动态给每行增加class属性的示例代码
作者:最初@
这篇文章主要介绍了el-table 动态给每行增加class属性的示例代码,代码简单易懂,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧
el-table 动态给每行增加class属性
html代码
row-class-name属性,绑定方法
:row-class-name=“tableRowClassName”,
<el-table :data="tableData" border :row-class-name="tableRowClassName"> </el-table>
js代码
tableRowClassName({row, rowIndex}),接受到两个参数
① row,行数据
② rowIndex, 行索引
tableRowClassName({row, rowIndex}) {
// 根据每行的数据,判断isError来增加class属性
if (row.row.isError === true) {
return 'warning-row'
} else {
return 'success-row'
}
// 根据行索引判断,增加class属性
if (rowIndex === 1) {
return 'warning-row';
} else if (rowIndex === 3) {
return 'success-row';
}
return '';
}css代码
<style lang="scss" scoped>
::v-deep .el-table .warning-row {
color: #f24835 !important;
td{
color: #f24835 !important;
}
}
::v-deep .el-table .success-row{
color: #00c617 !important;
td{
color: #00c617 !important;
}
}
</style>到此这篇关于el-table 动态给每行增加class属性的文章就介绍到这了,更多相关el-table 增加class属性内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
