Cannot read properties of undefined (reading ‘key‘)

这篇具有很好参考价值的文章主要介绍了Cannot read properties of undefined (reading ‘key‘)。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

如标题所示错误,直译是key为undefined。本次是因为使用了element-ui中的el-table组件所以并不是key为undefined,而是后台返回的key有重复。

当key重复就会出现页面卡死的现象,渲染就会失败。

key在使用时我们要注意:

1.在渲染时该识别为不同时,识别为相同

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() + ''
  }
}文章来源地址https://www.toymoban.com/news/detail-436513.html

到了这里,关于Cannot read properties of undefined (reading ‘key‘)的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • 解决Cannot read properties of undefined (reading ‘resetFields‘)

    第一天做项目中遇到了这一个问题关于resetField重置校验报错的问题,   然后去网上查找问题的原因,但是找到问题的原因是: mouted加载table数据以后,隐藏的 Dialog 并没有编译渲染进 dom 里面。所以当通过点击事件,Dialog 弹出的时候,$refs 并没有获取到 dom 元素导致 ‘reset

    2023年04月23日
    浏览(68)
  • [已解决]Cannot read properties of undefined (reading ‘install‘)

    唉,对于计算机的bug是真的很害怕。但是这个错误,我发现解决起来还是蛮简单的。 参考这篇博客: (2条消息) 错误“Cannot read properties of undefined (reading ‘install‘) at Vue.use” 的解决方案_cannot read properties of undefined (reading \\\'inst_FunSober的博客-CSDN博客 原因主要就是我们在下载

    2024年02月13日
    浏览(32)
  • TypeError: Cannot read properties of undefined (reading ‘replace‘)

    错误一:TypeError: Cannot read properties of undefined (reading \\\'replace\\\') 错误二:[Vue warn]: inject() can only be used inside setup() or functional conponents. 解释:当我们使用内置 use开头的钩子函数时,不能进行嵌套去拿实例。如: 解决:必须在 setup函数 第一层调用。

    2024年02月11日
    浏览(35)
  • TypeError: Cannot read properties of undefined (reading ‘map‘)

    控制台报错 TypeError: Cannot read properties of undefined (reading \\\'map\\\') 我的错误原因: 第一次页面渲染的时候,map的对象是undefined或null, 解决方法: 在前面加个要进行判断,当有值时再去遍历

    2024年02月07日
    浏览(38)
  • Uncaught TypeError: Cannot read properties of undefined (reading ‘remove‘)

    在Vue 3中,你可能会遇到“Uncaught TypeError: Cannot read properties of undefined (reading \\\'remove\\\')”这样的错误,这通常是因为在组件销毁时,尝试访问已经被销毁的元素或事件监听器。 为了解决这个问题,你可以在组件销毁之前,确保移除所有的事件监听器和其他可能导致问题的操作。

    2024年01月20日
    浏览(51)
  • Uncaught TypeError: Cannot read properties of undefined (reading ‘use‘)

    报错:Uncaught TypeError: Cannot read properties of undefined (reading ‘use’) 原因:Vue-router版本问题,在vue-router3可在router/index.js中安装router插件,但4不支持 解决: 1、在router/index.js中,导出{createRouter, createWebHistory}两个函数 使用createRouter来创建路由对象 使用createWebHistory函数赋值给histor

    2024年02月13日
    浏览(33)
  • TypeError: Cannot read properties of undefined (reading ‘NAME‘)报错解决

    问题描述:前端一个el-table表格,一个医院查询到的科室从后端返回时总是显示不出来,response里面是有数据的,这个表格别的医院都能显示出科室,就那个医院显示不出。报错:TypeError: Cannot read properties of undefined (reading \\\'NAME\\\')  查找问题所在,发现el-table里面有一个:formatte

    2024年02月01日
    浏览(40)
  • Vue报错 Cannot read properties of undefined (reading ‘websiteDomains‘) 解决办法

    浏览器控制台如下报错: Unchecked runtime.lastError: The message port closed before a response was received. Uncaught (in promise) TypeError: Cannot read properties of undefined (reading \\\'websiteDomains\\\')     at xl-content.js:1:100558 此问题困扰了很久,偶然看到一篇博文,说是迅雷扩展问题 要想解决这个bug最有效的方

    2024年04月24日
    浏览(32)
  • 前端解决 TypeError: Cannot read properties of undefined (reading ‘_c‘)

    每当打开页面包含有这个vue-json-viewer插件的JSON格式文件时,我本地代码运行是正常不报错的,但是线上的就会有报错问题 本地的正常显示   线上的显示,JSON是显示不出来  原因是vue-json-viewer插件的版本有问题,重新下载

    2024年02月08日
    浏览(87)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包