Custom event handler are missing from $attrs
Version
3.2.23
Reproduction link
Steps to reproduce
- Create a custom component
- Apply a listener for a custom event (e.g.
@custom="..."
and@other="..."
as per the example) - Observe how these are listed in
$attrs
of the component as$attrs.onCustom
,$attrs.onOther
etc. - Now implement the custom event by adding
emits: ['custom']
to the custom component - Observe how
$attrs.onCustom
is now undefined - As a result, there appears to be no way to detect if a custom event listener is present on a component or not
What is expected?
For custom event listeners to show up in $attrs
even if the component has them in its emits
array.
What is actually happening?
The listener is undefined
Refer to https://stackoverflow.com/questions/46706737/check-if-a-component-has-an-event-listener-attached-to-it for more details on the use case etc.
they are missing just like declared props are missing from $attrs.
We have an open issue about this already where we noted that we might consider a way to access cust event listeners like you can access props. Can't find it right now though.
For now, you can declare the listener as a prop with on* prefix (which is how listeners are passed under the hood anyway), then you can check props.onCustom
.
Alright thanks, if you can find the open issue so that I (or anyone finding this in the future) can track the progress for it that would be much appreciated.