首页IT科技cannot read properties null(Cannot read properties of undefined (reading ‘key‘))

cannot read properties null(Cannot read properties of undefined (reading ‘key‘))

时间2025-05-21 15:17:12分类IT科技浏览5310
导读:如标题所示错误,直译是key为undefined。本次是因为使用了element-ui中的el-table组件所以并不是key为undefined,而是后台返回的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() +

  }

}

创心域SEO版权声明:以上内容作者已申请原创保护,未经允许不得转载,侵权必究!授权事宜、对本内容有异议或投诉,敬请联系网站管理员,我们将尽快回复您,谢谢合作!

展开全文READ MORE
b站up退站(抖音进攻,B站退守)