TypeError: Cannot read properties of null (reading 'name')

发布时间 2023-05-19 19:57:34作者: 周文豪

报错如下:

错误代码:

searchList() {
      this.entity = {}
      this.edit = null
      
      let query = {}
      query.traceCode = this.code
      this.loading = true
      codeApi.queryTraceCode(query).then(res => {
        ...
      }, err => {
        console.error(err)
      }).finally(() => {
        this.loading = false
      })
    },

数据模型:

data() {
    return {
      edit: {
        name: '',
        prepnSpec: null,
        pkgSpec: null,
        expiryTem: null,
        approvalLicenceNo: null,
        produceDate: null,
        expiryDate: null,
        batchNo: null,
        produceEntName: null,

      },

    }
  },

解决办法:

searchList() {
      this.entity = {}
      this.edit = {}
      
      let query = {}
      query.traceCode = this.code
      this.loading = true
      codeApi.queryTraceCode(query).then(res => {
        ...
      }, err => {
        console.error(err)
      }).finally(() => {
        this.loading = false
      })
    },