先上目标效果图,按需观看
后端返回数据的数据格式
前端处理
table表格
数据请求
let dataYt = await Home.getProductRelease();//数据请求
let data = dataYt.data;
if (data && dataYt.code===200) {
this.productFlag = false;
for (const v of data) {
for (const k of v.product) {
let param = {
name: v.groupName,
moduleName: k.name,
releaseNum:k.releaseNum,
keyVersion:k.keyVersion
}
this.product.push(param);
}
}
for (let i = 0; i < data.length; i++) {
this.number.push({
name:data[i].groupName,
num:data[i].product.length
})
}
let msgIndex = 0;
let msgArr = [];
for (let i = 0; i < this.number.length; i++) {
let num = this.number[i].num;
msgIndex += num;
msgArr.push(msgIndex);
}
msgArr.pop();
msgArr.unshift(0);
for (let i = 0; i < this.number.length; i++) {
let num = this.number[i].num;
this.product[msgArr[i]].rowspan = num;
}
}
处理后的数据(注意红框的rowsoan)
结合:span-method
:span-method="objectSpanMethod"
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
if (columnIndex === 0) {
if (row.rowspan >= 1) {
return {
rowspan: row.rowspan,
colspan: 1
};
} else {
return {
rowspan: 0,
colspan: 0
};
}
}
}