这里是多个表格循环
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/fca4249c2e0c4ccfa87bcb3c14f0a863.png)
html部分
<div v-for="item in tableData">
<el-table
:data="item.checkProjects"
style="width: 100%"
border
:span-method="objectSpanMethod(item.checkProjects)"
>
<el-table-column prop="name" label="点检部位" />
<el-table-column prop="checkName" label="点检内容及标准" />
<el-table-column prop="checkMethod" label="点检方法" />
<el-table-column prop="standard" label="标准值" />
</el-table>
</div>
JS部分
## 部分数据
tableData: [
{
checkProjects: [
{standard: "是", name: "变频器", checkMethod: "看", checkName: "自带冷却风扇是否运转正常", contentType: 3},
{ standard: "40", name: "变频器", checkMethod: "测", checkName: "温度<40℃", contentType: 2 },
{ standard: "否", name: "接触器", checkMethod: "听", checkName: "有无异响", contentType: 3 },
{ standard: "是", name: "接触器", checkMethod: "看", checkName: "吸合分断是否正常", contentType: 3 },
]
},
// Add more data for other tables...
]
方法部分
objectSpanMethod(data) {
return ({ row, column, rowIndex, columnIndex }) => {
if (columnIndex === 0) {
const prevRow = data[rowIndex - 1];
if (prevRow && row.name === prevRow.name) {
return {
rowspan: 0,
colspan: 1,
};
} else {
let rowspan = 1;
for (let i = rowIndex + 1; i < data.length; i++) {
if (data[i].name === row.name) {
rowspan++;
} else {
break;
}
}
return {
rowspan,
colspan: 1,
};
}
}
};
},