Vue: Equivalent for this.$listeners for native events?

Created on 22 Mar 2019  Â·  5Comments  Â·  Source: vuejs/vue

What problem does this feature solve?

Imagine a wrapper component where you need to pass events to a child component. This is possible for non native events using this.$listeners, but it strips out native events. It would be good if we had something like this.$nativeListeners so that we can pass native events down to child components as well.

In the meantime, Is there a workaround to pass events to child components?

What does the proposed API look like?

this.$nativeListeners

feature request

Most helpful comment

Note they will still be bound to the root element though and that you should avoid reading $vnode in general and never modify it

All 5 comments

Maybe something like inheritNativeListeners: true (that default to false) to go in pair with inheritAttrs

Native listeners are available in functional components but are passed to the root of the component in regular components

Thanks for the reply! Is there a workaround to get the native events out of the root?

not that i'm aware of

@DM2489

Is there a workaround to get the native events out of the root

You can access them in this.$vnode.data.nativeOn

Note they will still be bound to the root element though and that you should avoid reading $vnode in general and never modify it

Was this page helpful?
0 / 5 - 0 ratings