Home > front end >  Send parameter from subchild component to parent component
Send parameter from subchild component to parent component

Time:08-25

I have this structure of components

Parent Component --> Child Component --> SubChild Component

So, in the sub-child component I have an $emit event as:

   <HTMLTag
            @input="$emit('update:table-range', $event)"
          />

So I can receive it on the child component as:

 <SubChildComponent
      @update:table-range="onUpdateFilter"
    />

But I do not want to use on child component, I want to use on the parent, how can I send it thought the child to the parent?

ParentComponent:

  <ChildComponent @update:table-range="onUpdateFilter" />

This does not work

Regards

CodePudding user response:

Emit it again from the Child component

<SubChildComponent
      @update:table-range="$emit('update:table-range', $event)"
/>

By the way, when you start passing data between multiple levels of components, you may want to instead consider a state management library such as Vuex which provides a single central location for data that all components can easily access.

  • Related