
el-table表格通过:span-method="objectSpanMethod" 可以设置合并单元格
表格数据
tableData: [
{
id: 1,
name: 111,
isInputS: true
},
{
id: 1,
name: 111,
isInputS: true
},
{
id: 1,
name: 111,
isInputS: true
},
{
id: 2,
name: 222,
isInputS: true
},
{
id: 3,
name: 222,
isInputS: true
},
{
id: 3,
name: 222,
isInputS: true
}
],
spanArr: [],
mounted() {
let contactDot = 0;
this.tableData.forEach( (item,index) => {
if(index===0){
this.spanArr.push(1)
}else{
if(item.id === this.tableData[index-1].id){
this.spanArr[contactDot] += 1;
this.spanArr.push(0)
}else{
contactDot = index
this.spanArr.push(1)
}
}
})
},
methods: {
objectSpanMethod ({ row, column, rowIndex, columnIndex }) {
// return
if(columnIndex === 0){
const _row = this.spanArr[rowIndex]
const _col = _row>0?1:0;
return{
rowspan:_row,
colspan:_col
}
}
if(columnIndex === 1){
const _row = this.spanArr[rowIndex]
const _col = _row>0?1:0;
return{
rowspan:_row,
colspan:_col
}
}
},
}