vue中 报错 Cannot read property 'push' of undefined" 是什么原因

如题,不知道怎么 我调用组件的时候就报出这个错误了

<slide-out
      dock="right"
      :visible="slideOutAttr.visiblity"
      :size="slideOutAttr.size"
      :z-index="10"
      @close="onClose"
    >
      <div slot="header" slot-scope="title">{{ title }}</div>
      <AssignAE :code-list="codeList" :visible="slideOutAttr.visiblity" :on-close="onClose" :save-callback="saveCallBack" :assign-id="slideOutAttr.selectedAssignId" />
    </slide-out>
// 信息-添加行
      addNewDetail () {
        const that = this
        that.generateId();
        that.generateSerialNumber();
        that.assignInfoList.orderAssignInfo.push({
          detailId: that.tempId,
          serialNumber: that.serialNo
        })
        console.log(that.tempId)
        console.log(that.serialNo)
        // console.log(that.assignInfoList)
      },
      // 信息-删除行
      deleteDetail (row) {
        const that = this
        that.assignInfoList.splice(row.index, 1)
        for (let i = 0; i < that.assignInfoList.length; i++) {
          that.assignInfoList[i].serialNumber = i + 1
          that.serialNo = i + 1
        }
      },
阅读 8.3k
2 个回答

建议查一下空值,that.assignInfoList.orderAssignInfo 空值的情况下是 undefined,就会报这个错误。

that.assignInfoList[i].serialNumber = i + 1 看这句 that.assignInfoList 应该是数组

that.assignInfoList.orderAssignInfo 难道不应该是个 undefined 吗?
有可能你是想写 that.assignInfoList.push

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题