Skip to content

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

Description

@wong-lucy

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));
  }
},

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions