table 添加方法
:span-method="objectSpanMethod"
JS 方法
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
if (columnIndex === 4) {
const _row = this.spanArr[rowIndex]
const _col = _row > 0 ? 1 : 0
return {
rowspan: _row,
colspan: _col
}
}
},
合并(在mounted方法中调用this.tableDatas())
tableDatas() {
let contactDot = 0
this.spanArr = []
this.tableData.forEach((item, index) => {
item.index = index
if (index === 0) {
this.spanArr.push(1)
contactDot = 0
} else {
if (item.modelName === this.tableData[index - 1].modelName) {
// modelName 是绑定的字段名
this.spanArr[contactDot] += 1
this.spanArr.push(0)
} else {
this.spanArr.push(1)
contactDot = index
}
}
})
},