Description
Version
3.0.7
Reproduction link
https://codesandbox.io/s/recursive-emit-bug-10073
Steps to reproduce
See codesandbox for illustration of the problem
- Create a recursive component that has an 'emits: ["event"]'
- Emit a custom event
$emit("event", depth)
from recursive component - Add
v-bind="$attrs"
to every recursive inclusion from recursive component to enable emitting from any level - Finally use the recursive component with an
@event="..."
handler
What is expected?
The @event="..."
is called for any "depth"
What is actually happening?
Only the first (top level) of the recursive component is handled
I spent some hours debugging this issue. According to documents we should add emits: ["<name>"]
to our components. However, by doing so, we capture the event listener and effectively remove it from $attrs
at the first "level".
The system behaves according to specifications, but it feels wrong to have to leave out emits: ["<name>"]
when you build an emitting recursive component. At least for me it was very counter-intuitive.
Sadly I do not have a good solution as I understand why you capture any defined props and emits from the $attrs
. However, maybe I am just not doing it right, would love to hear how we should create an emitting recursive component.
P.S. I found this problem when I was creating a file explorer component using a single recursive component.