美文网首页
watch带来的问题

watch带来的问题

作者: 不退则进_笑 | 来源:发表于2024-09-22 19:59 被阅读0次
 watch: {
    defaultData: {
      handler(val) {
        if (val) {
          console.log("======引用数据会再次触发watch变化======", val);
          this.description = val.description;
          this.parameterList = val.parameterList;
          this.barCode = val.barCode;
        }
      },
      deep: true,
      immediate: true,
    },
  },

背景:客户反馈,操作description之后,在把鼠标移动到parameterList,description里的值会变成原先数据
结果:是因为parameterList是引用类型,parameterList发生改变,会重新触发defaultData,然后导致description会被重新赋予初始值,所以客户看到好像description值会变成原先数据
注意:以后避免watch里含有对引用类型数据的变更,最好都是原始类型

相关文章

网友评论

      本文标题:watch带来的问题

      本文链接:https://www.haomeiwen.com/subject/fwrxrjtx.html