Subscribe on changes!

How can the actions of Vue's children (grandchildren) trigger directly to grandparent (or more) components? Does vue3.0 have a similar way to $parent?

avatar
Sep 4th 2020

What problem does this feature solve?

What does the proposed API look like?

How to make the events of el-form-item component pay directly to the el-form component。

I hope there's something like this: this.dispatch('ElFormItem', 'el.form.blur', [this.value]); ...

dispatch(componentName, eventName, params) { var parent = this.$parent || this.$root; var name = parent.$options.componentName;

  while (parent && (!name || name !== componentName)) {
    parent = parent.$parent;

    if (parent) {
      name = parent.$options.componentName;
    }
  }
  if (parent) {
    parent.$emit.apply(parent, [eventName].concat(params));
  }
},
avatar
Sep 4th 2020

Use Vuex or a shared reactive object with provide/inject. Don't reach for parent like that.

avatar
Sep 9th 2020

Use Vuex or a shared reactive object with provide/inject. Don't reach for parent like that.

thanks!!!I solved the problem。