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
        }
      },
已解决 悬赏分:50 - 解决时间 2022-01-04 16:12
反对 0举报 0 收藏 0

回答2

最佳
  • @

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

    支持 0 反对 0 举报
    2022-01-04 08:48
  • @

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

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

    支持 0 反对 0 举报
    2022-01-04 09:43