el-table合并单元
1、data中定义两个字段
spanArr: [], // 用于存储每个单元格的 rowspan 和 colspan
pos: 0, // 用于记录当前合并单元格的起始位置
2、methods中声明两个方法
getSpanArr(data) {this.spanArr = [];this.pos = 0;for (let i = 0; i < data.length; i++) {if (i === 0) {this.spanArr.push(1);this.pos = 0;} else {if (data[i].pumpType === data[i - 1].pumpType) {this.spanArr[this.pos] += 1;this.spanArr.push(0);} else {this.spanArr.push(1);this.pos = i;}}}
},// 合并单元格
objectSpanMethod({ row, column, rowIndex, columnIndex }) {if ([1, 2, 7, 8, 9, 10].includes(columnIndex)) {const _row = this.spanArr[rowIndex];const _col = _row > 0 ? 1 : 0;return {rowspan: _row,colspan: _col;}
}
3、从接口获取到表格数据后,立即调用this.getSpanArr(this.tableData);方法,并且
4、最终效果: