My Vue components are structured as follows:
<TopParent> <!-- Listening for events from EventProducer here -->
<Child_1>
<Child_2>
<Child_3>
...
<Child_N>
<EventProducer /> <!-- Emitting events here -->
</Child_N>
</Child_3>
</Child_2>
</Child_1>
</TopParent>
Query
Is it possible to emit
an event in the <EventProducer>
component and then listen to that event in the <TopParent>
component?
How can I instruct all
<Child_1>...<Child_N>
components to simply forward the event to their parent?
P.S. I am looking for a solution where I don't need to specify the exact names of the events, but rather forward all events.
A possibly inadequate workaround
A basic approach could be something like this. Yet, it becomes quite verbose, especially with multiple events:
<TopParent @foo="doTheJob()">
<Child_1 @foo="emit('foo')">
<Child_2 @foo="emit('foo')">
<Child_3 @foo="emit('foo')">
...
<Child_N @foo="emit('foo')">
<EventProducer @click="emit('foo')"/>
</Child_N>
</Child_3>
</Child_2>
</Child_1>
</TopParent>
I am optimistic that there might be a more efficient way to achieve this.