根据提供的代码,表单项 'acTaxableincome' 没有反应的原因是因为在计算属性 'acTaxableincome' 中,对表单项 'this.form' 进行了赋值操作,但是并没有触发表单项的更新。Vue 的计算属性并不会自动更新依赖的属性,需要手动触发更新。

解决方法是将赋值操作放在 Vue 的 '$nextTick' 回调函数中,以确保在下一次 DOM 更新循环之前进行赋值操作,从而触发表单项的更新。代码修改如下:

acTaxableincome: function() {
  const { disposableCompensationIncome, taxExemptIncome, subtotal, deductionAllowedDonate } = this.form;
  const taxableAmount = disposableCompensationIncome - taxExemptIncome - subtotal - deductionAllowedDonate;

  this.$nextTick(() => {
    this.form.acTaxPiPersonCalculationSchedule.acTaxableIncome = taxableAmount >= 0 ? taxableAmount : 0.0;
  });

  return this.form.acTaxPiPersonCalculationSchedule.acTaxableIncome;
},

这样修改后,当计算属性 'acTaxableincome' 被访问时,会先更新表单项的值,然后再返回该值。

另外,如果你使用的是 Vue 3 版本,可以使用 'await this.$nextTick()' 来等待 DOM 更新。代码修改如下:

acTaxableincome: async function() {
  const { disposableCompensationIncome, taxExemptIncome, subtotal, deductionAllowedDonate } = this.form;
  const taxableAmount = disposableCompensationIncome - taxExemptIncome - subtotal - deductionAllowedDonate;

  await this.$nextTick();

  this.form.acTaxPiPersonCalculationSchedule.acTaxableIncome = taxableAmount >= 0 ? taxableAmount : 0.0;

  return this.form.acTaxPiPersonCalculationSchedule.acTaxableIncome;
},
Vue 表单 acTaxableincome 无法更新的解决方法

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

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