JS - el-table - :row-key
2022-03-25 •
2 条评论
getRowKey(row) {
/** 检查row.id是否有重复的缓存对象 */
if (!this.checkRepeatObj) {
this.checkRepeatObj = {}
}
if (row) {
if (row.id) {
if (this.checkRepeatObj[row.id]) {
if (!row._secondId) {
row._secondId = Math.random() + ''
}
/** 方便根据key重用元素 */
return row._secondId
} else {
this.checkRepeatObj[row.id] = 1
return row.id
}
}
console.log('row.id为空')
if (!row._secondId) {
row._secondId = Math.random() + ''
}
return row._secondId
} else {
console.log('row为空')
return Math.random() + ''
}
}