vue Object.assign 导致数据回填,输入框不可以输入,也不可以删除值。

1、业务场景,在页面中,监听输入框值改变,就将值存入本地缓存。下次进入页面的时候,提醒用户还有没保存的数据,是否立即编辑。

2、代码如下:

 watch: {
      form: {
        handler(newVal) {
          this.saveForm();
        },
        deep: true
      },
      otherForm: {
        handler(newVal) {
          this.saveForm();
        },
        deep: true
      }
}
 methods: {
    saveForm() {
        let self = this;
        let form = Object.assign(self.form, self.otherForm);
        localStorage.setItem("form", JSON.stringify(form));
    },
},

3、解决:

      saveForm() {
        let self = this;
        let formbrefore = JSON.parse(JSON.stringify(self.form))
        let form = Object.assign(formbrefore, self.otherForm);
        localStorage.setItem("form", JSON.stringify(form));
      },

 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值