Subscribe on changes!

Listeners declared in emits array are inacessible

avatar
Sep 30th 2021

Version

3.2.19

Reproduction link

sfc.vuejs.org/

Steps to reproduce

Uncomment the emits array declaration in VirtualForm component

What is expected?

Refering to the documentation: https://v3.vuejs.org/guide/migration/listeners-removed.html, the listeners should be available as keys of the this.$attrs object

What is actually happening?

The listeners are not available.

avatar
Sep 30th 2021

By defining the emits, you ensure they are not passed to $attrs. This is intentional.

avatar
Sep 30th 2021

Thanks for quick response.

My point is that all undeclared properties are available in the $attrs. As soon as the property is declared it is available somwhere else, but with the listeners declaration (including in emits) makes a listener "unaccessible". So what is the solution here? Should I simply exclude listener from emits if I want to acess it somewhere in the code? Is it "safe"? - because vue emits the warning.

avatar
Oct 1st 2021

In order to check if it exists, you should declare it as a prop: https://github.com/vuejs/rfcs/pull/154#issuecomment-614724480