合并单元格后,由于多行合并,隔行变色效果失效

一、实现效果,合并的多行同一颜色,如图:

请添加图片描述

二、实现原理:根据后端数据的id,本质就是多条数据合并单元格,所以这几个数据有相同的id,相同id的数据行设置同一颜色

1、首先在tr上面添加:style="getRowStyle(value.id)"实现动态style绑定,传id
<tr v-for="(value, index) in obj" :key="index" :style="getRowStyle(value.id)">
</tr>
2、在data中定义颜色对象
data() {  
    return {  
      // 用于跟踪已分配的颜色  
      usedColors: {}  
    };  
  },  
3、然后实现getRowStyle方法
methods: {
	getRowStyle(id) {
        let color = this.usedColors[id];
        if (!color) {
          const colors = ['rgb(255, 255, 255)', 'rgb(244, 244, 244)'];
          const index = Object.keys(this.usedColors).length % colors.length;
          color = colors[index];
          this.usedColors[id] = color;
        }
        return `background-color: ${color};`;
      },
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值