Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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? #2044

Closed
wong-lucy opened this issue Sep 4, 2020 · 2 comments

Comments

@wong-lucy
Copy link

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));
  }
},
@yyx990803
Copy link
Member

yyx990803 commented Sep 4, 2020

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

@wong-lucy
Copy link
Author

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

thanks!!!I solved the problem。

@github-actions github-actions bot locked and limited conversation to collaborators Nov 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants