功能要求:需要给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列表给指定列的文字添加样式,但是列是动态的


基础教程推荐
猜你喜欢
- js开发中的页面、屏幕、浏览器的位置原理(高度宽度)说明讲解(附图) 2023-12-21
- js实现的美女瀑布流效果代码 2023-12-19
- HTML基础知识学习(1) 2023-10-26
- html+css实现血轮眼轮回眼特效代码 2022-09-20
- vue-cli4 配置gzip 2023-10-08
- 浅析JS刷新框架中的其他页面 && JS刷新窗口方法汇总 2024-01-07
- 详解CSS3中强大的filter(滤镜)属性 2024-02-07
- js 上下左右键控制焦点(示例代码) 2024-01-05
- Vue如何实现组件的预加载 2025-01-13
- vue项目中如何调用this.$nextTick()方法 2025-01-13