功能要求:需要给el-table
中的其中一列的新增颜色(不同类型不同颜色),但是这列的位置是根据不同用户变化的,用户A登录在第二列、用户B登录在第七列。
<el-table :data="listData" v-loading="dataLoading" :cell-class-name="myclass"></el-table>
解决方法:
myclass({ row, column, rowIndex, columnIndex }) {
//在需要属性中判断
if (column.property === 'type') {
//需要拿到id="el-table_1_column_1" 最后的数字-1就是当前的位置
const columnArr = column.id.split('_')
let currentIndex = Number(columnArr[columnArr.length - 1]) - 1 //获取type属性位置
//根据不同类型判断
if (row.type == '语文' && columnIndex === currentIndex) {
return 'color1'
} else if (row.type == '英文' && columnIndex === currentIndex) {
return 'color2'
} else if (row.type == '数学' && columnIndex === currentIndex) {
return 'color3'
} else if (row.type == '体育' && columnIndex === currentIndex) {
return 'color4'
} else if (row.type == '自习' && columnIndex === currentIndex) {
return 'color5'
}
}
}
以上是编程学习网小编为您介绍的“el-table列表给指定列的文字添加样式,但是列是动态的”的全面内容,想了解更多关于 vuejs 内容,请继续关注编程基础学习网。
沃梦达教程
本文标题为:el-table列表给指定列的文字添加样式,但是列是动态的


猜你喜欢
- jquery中cookie用法实例详解(获取,存储,删除等) 2024-03-01
- Google Chrome浏览器无法显示hover样式的解决方法 2024-02-07
- layui formSelects实现下拉框select多选,并且编辑时候回显 2023-11-18
- 从gb到utf-8 2022-11-04
- 详解iframe跨域的几种常用方法(小结) 2023-12-25
- css之Display、Visibility、Opacity、rgba和z-index: -1的区别 2024-02-24
- 详解CSS中zoom属性或overflow:auto属性清除浮动的作用 2024-02-07
- JS开发 富文本编辑器TinyMCE详解 2023-12-26
- HTML5 本地存储之如果没有数据库究竟会怎样 2024-03-09
- JS中null和undefined的区别 2023-07-09