如何在Vue中使用MutationObserver监听componentInstance对象变化?

mounted() {

new MutationObserver(this.handleReturn).observe(
  this.$slots.default[this.$slots.default.length - 1].componentInstance.$children[0].$el,
  {
    attributes: true,
  }
);

},
methods: {

handleClick(event) {
  event.stopPropagation();
},
handleReturn() {
  for (let i = 0; i < this.$slots.default.length; i++) {
    if (this.$slots.default[i].componentInstance) {
      if (this.$slots.default[i].componentInstance[this.bindValue] && Object.keys(this.$slots.default[i].componentInstance[this.bindValue]).length !== 0) {
        if (
          !this.shallowEqual(this.$slots.default[i].componentInstance[this.bindValue],
            this.dataInternal)
        ) {
          this.dataInternal =
            this.$slots.default[i].componentInstance[this.bindValue];
            console.log("this.keyEid",this.keyEid);
            console.log("this.keys",this.keys);
          if (this.keyEid !== undefined && this.keys !== undefined) {
            this.$emit("update:keyEid", this.dataInternal[this.keys]);
          }
          this.$emit("input", this.dataInternal);
        }
      }
    }
  }
},

}

发现如果componentInstance中修改了对象本身 , 而不是修改原对象 的属性 , 获取的对象是原来的对象 , 而不是现在的对象 , 就无法响应 , 应该如何处理呢

阅读 340
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题