Opt-in events bubbling #581
Replies: 4 comments 5 replies
-
If I recall correctly, this bubbling behavior was intentionally removed in past versions of Vue |
Beta Was this translation helpful? Give feedback.
-
Just edited the proposal with the term "bubble" instead, since it's the most common term. |
Beta Was this translation helpful? Give feedback.
-
I don't think the event actually bubbles, isn't it more that undeclared event handlers are inherited in the same way that attrs are? As an alternative when I need bubbling, I use native HTML events. |
Beta Was this translation helpful? Give feedback.
-
Hi everybody. I landed here to find a solution to this problem and the original post idea inspired me to build a simple plugin that simulates the DOM event bubbling and, at the same time, keeping things separated from Vue core event system. |
Beta Was this translation helpful? Give feedback.
-
What problem does this feature solve?
None. It would only be a syntax sugar.
Sometimes we need to reemit events that are coming from a child component all the way up to a parent component where the event will be in fact handled. Depending on the situation, Vuex/Pinia may not be suitable.
For example:
It would work as expected because Vue bubbles events by default. But there's a gotcha. Vue only does that if there is no explicit declared event with the same name on the component.
It stops working when we need to emit the same event in the
ComponentB
, like this:So, we need to do this:
Doing something like this is not the end of the world, but at least for me it looks like unnecessary code. And can get worst if there are two or more reemits.
What does the proposed API look like?
At first I thought a general option in the app config would be sufficient, but it wouldn't be much flexible. So, instead I thought of this:
Beta Was this translation helpful? Give feedback.
All reactions