1、页面效果
2、table
3、
watch: {
implementationList: {
handler(n, o) {
this.getSpanArr(this.implementationList)
},
immediate: true
}
},
methods: {
//合并行
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
// columnIndex === xx 找到第xx列,实现合并随机出现的行数
if (columnIndex === 1 || columnIndex === 2) {
const _row = this.spanArr[rowIndex];
const _col = _row > 0 ? 1 : 0;
return {
rowspan: _row,
colspan: _col
};
}
},
// 因为要合并的行数是不固定的,此函数是实现合并随意行数的功能
getSpanArr(data) {
console.log("zmmm--",data)//从后台获取的数据
this.spanArr = [];
this.pos = 0;
for (var i = 0; i < data.length; i++) {
if (i === 0) {
// 如果是第一条记录(即索引是0的时候),向数组中加入1
this.spanArr.push(1);
this.pos = 0;
} else {
if (data[i].itemCode === data[i - 1].itemCode || data[i].itemName === data[i - 1].itemName) {
// 如果itemCode相等就累加,并且push 0
this.spanArr[this.pos] += 1;
this.spanArr.push(0);
} else {
// 不相等push 1
this.spanArr.push(1);
this.pos = i;
}
}
}
},
}
版权声明:本文为xiongdaandxiaomi原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。