Skip to content

Using the recommended emit attribute removes the event namespace from the component attributes #5319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
twickstrom opened this issue Jan 24, 2022 · 4 comments

Comments

@twickstrom
Copy link

Version

3.2.29

Reproduction link

stackblitz.com

Steps to reproduce

Create a component.

In the component add the emits option: emits: ['onDelete']
In the components template add an if statement to determine if the event is bound to the component v-if="$attrs.onOnDelete"

In the parent add an event handler such as @click="onDelete"

What is expected?

In the Vue3 docs it recommends to define what events a child component can emit to the parent https://v3.vuejs.org/guide/migration/emits-option.html#overview

If the parent binds the event onDelete I would expect the component to be displayed.

What is actually happening?

The component is not displayed.


See the discussion here: https://stackoverflow.com/questions/70272335/vue3-check-if-event-listener-is-bound-to-component-instance/70358655?noredirect=1#comment125169175_70358655

@sqal
Copy link
Contributor

sqal commented Jan 24, 2022

Declare it as as prop onDelete: Function. You will be able to check for existence, and still use emit('delete')

duplicate - #5220
example

@twickstrom
Copy link
Author

Declare it as as prop onDelete: Function. You will be able to check for existence, and still use emit('delete')

duplicate - #5220

Agreed, there are a few work arounds. However I feel that lacking a way to check what is an allowed emit, per the documentation, especially as it pertains to more complex examples with multiple events, makes the recommendation of using the emits to define what can be emitted a bit useless.

Vue 3 now offers an emits option, similar to the existing props option. This option can be used to define the events that a component can emit to its parent.

Wouldn't it add value to this feature to add the allowed emitted values to the attrs? Or, access them via $emits or $emittable.

What is the technical or performance limitation to do so?

@lidlanca
Copy link
Contributor

lidlanca commented Jan 24, 2022

make your case in the RFC discussion, if it wasn't already made.
vuejs/rfcs#397

and don't hold your breath

@posva
Copy link
Member

posva commented Feb 9, 2022

Duplicate of #5220

@posva posva marked this as a duplicate of #5220 Feb 9, 2022
@posva posva closed this as completed Feb 9, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Oct 3, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants