如標(biāo)題所示錯(cuò)誤,直譯是key為undefined。本次是因?yàn)槭褂昧薳lement-ui中的el-table組件所以并不是key為undefined,而是后臺(tái)返回的key有重復(fù)。
當(dāng)key重復(fù)就會(huì)出現(xiàn)頁(yè)面卡死的現(xiàn)象,渲染就會(huì)失敗。
key在使用時(shí)我們要注意:
1.在渲染時(shí)該識(shí)別為不同時(shí),識(shí)別為相同
2.在渲染時(shí)該識(shí)別為相同,卻識(shí)別為了不同
解決問(wèn)題如下:文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-436513.html
? getRowKey(row) {
? /** 檢查row.id是否有重復(fù)的緩存對(duì)象 */
? if (!this.checkRepeatObj) {
? ? this.checkRepeatObj = {}
? }
? if (row) {
? ? if (row.id) {
? ? ? if (this.checkRepeatObj[row.id]) {
? ? ? ? if (!row._secondId) {
? ? ? ? ? row._secondId = Math.random() + ''
? ? ? ? }
? ? ? ? /** 方便根據(jù)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() + ''
? }
}文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-436513.html
到了這里,關(guān)于Cannot read properties of undefined (reading ‘key‘)的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!