el-table中使用span-method报错You may have an infinite update loop in a component render function.
时间: 2023-12-05 12:39:02 浏览: 120
使用VUE的el-table标签的_span-method=_arraySpanMethod_合并列中重复的单元格.md
在el-table中使用span-method时,如果出现报错"You may have an infinite update loop in a component render function.",通常是由于在span-method中更新了数据导致的。为了解决这个问题,可以将更新数据的操作放在异步方法中执行,例如使用Vue.nextTick()方法。具体操作如下:
```javascript
<el-table :data="tableData">
<el-table-column prop="name" label="Name" :span-method="handleSpanMethod"></el-table-column>
</el-table>
<script>
export default {
data() {
return {
tableData: [
{ name: 'John', age: 22 },
{ name: 'Mike', age: 25 },
{ name: 'Amy', age: 20 }
]
}
},
methods: {
handleSpanMethod({ row, column, rowIndex, columnIndex }) {
if (rowIndex === 0 && columnIndex === 0) {
return {
rowspan: 2,
colspan: 1
};
} else if (rowIndex === 1 && columnIndex === 0) {
return {
rowspan: 0,
colspan: 0
};
}
}
},
computed: {
...mapState({
// ...
})
},
watch: {
// ...
}
}
</script>
```
阅读全文