在 submitDetail 函数中,将 acTaxPiIncomeReportingDetail 的值存储到 submitForm 函数中的 form.acTaxPiIncomeReportingDetail 的实现方法,以及解决常见错误“Cannot read properties of null (reading 'gregorianCalendarDays')”的方案。

根据给出的代码,您在 submitDetail 函数中尝试将 acTaxPiIncomeReportingDetail 的值存储到 submitForm 函数中的 form.acTaxPiIncomeReportingDetail 中。但是报错提示为“Cannot read properties of null (reading 'gregorianCalendarDays')”,说明在存储值之前,acTaxPiIncomeReportingDetail 属性的值为 null。

这个问题可能是由于在 submitDetail 函数中,您在执行 this.form.acTaxPiIncomeReportingDetail = { ...this.form.acTaxPiIncomeReportingDetail } 时,将 acTaxPiIncomeReportingDetail 属性重新赋值为一个新的对象,导致之前的值被覆盖为 null。

为了解决这个问题,您可以在 submitDetail 函数中添加一个判断,检查 acTaxPiIncomeReportingDetail 属性是否为 null,如果是 null,则先将其初始化为一个空对象,然后再进行赋值操作。修改后的 submitDetail 函数如下:

submitDetail() {
  console.log(this.form.acTaxPiIncomeReportingDetail, 'ddddd');
  this.isViewMode = false;
  const formitems = [
    'gregorianCalendarDays',
    'domesticWorkDays',
    'abroadWorkDays',
    'totalRevenue',
    'domesticPayment',
    'abroadPayment',
  ];
  const formdata = this.form;
  console.log(formdata, 'fffffff')
  
  // 检查 acTaxPiIncomeReportingDetail 是否为 null,如果是 null 则初始化为一个空对象
  if (this.form.acTaxPiIncomeReportingDetail === null) {
    this.form.acTaxPiIncomeReportingDetail = {};
  }
  
  formitems.forEach((item) => {
    this.form.acTaxPiIncomeReportingDetail[item] = formdata.acTaxPiIncomeReportingDetail[item];
  });

  const income = this.calculateIncome();
  this.form.equityIncentiveIncome = income;
  this.dialogVisible = false;
},

通过添加这个判断,确保了 acTaxPiIncomeReportingDetail 属性不为 null,使得提交表单时不再报错。

Vue.js 中 submitDetail 函数将 acTaxPiIncomeReportingDetail 值存储到 submitForm 函数的 form.acTaxPiIncomeReportingDetail 中的实现方法

原文地址: https://www.cveoy.top/t/topic/pdun 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录