开发过程中用到了elementUI中table组件,合并单元格时遇到了You may have an infinite update loop in a component render function.
经排查发现时由于方法中 在data 中定义了变量firstName 并使用与改变了该变量的原因
尽量将变量定义到方法内
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
const length = this.list.filter(item => (item.firstName=== row.firstName)).length
if (this.firstName !== row.firstName) {
this.firstName = row.firstName
return {
rowspan: length,
colspan: 1
}
} else {
return {
rowspan: 0,
colspan: 0
}
}
}
objectSpanMethod({ row, column, rowIndex, columnIndex }) {
const length = this.list.filter(item => (item.firstName=== row.firstName)).length
const firstName = this.list[rowIndex - 1]?.firstName || '' 根据自己需要定义在方法内
if (firstName !== row.firstName) {
return {
rowspan: length,
colspan: 1
}
} else {
return {
rowspan: 0,
colspan: 0
}
}
}