Skip to content
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

Unintentional $event value setting on customized event #10945

Closed
GYHHAHA opened this issue May 14, 2024 · 2 comments
Closed

Unintentional $event value setting on customized event #10945

GYHHAHA opened this issue May 14, 2024 · 2 comments

Comments

@GYHHAHA
Copy link

GYHHAHA commented May 14, 2024

Vue version

latest

Link to minimal reproduction

https://play.vuejs.org/#eNp9UstOwzAQ/JWVhdRWKi0ITiEgHuoBDoCAoy8h2RaDX7Kd0CrKv7N2XwGh3uyd2Z2xZ1t2Y+2kqZFlLPelEzaAx1DbK66FssYFuPsQsnKoYe6MgsFkui3EtsHFjteCwzl0G9oG47o02gdQq8davaODy8ganowIy6drQZKiS0BlZRGQbgD5TvRarY6xQR0uOesNOUo1zqaJ3rZ7ga6Lk3vT2JgFTy7mYjH59EbTS9vYxFlplBUS3ZMNglxylkFCIlZIab4fUi24GsfbevmB5dc/9U+/jDXOnh16dA1ytsNC4RZIZiM8e33EJZ13oDJVLYl9AHxBb2QdPa5pt7WuyHaPl9zepxyEXrz52TKg9ttHRaOR2SU+Z5TN3YGn7+2eTc5TH9cd/WI/97/rArLQC4oo0Cj683XoqETwFFaFc6FxFm95UhliBgO1msUMB2OwhStUBjoFOMqgMaKi/eiuhgfXJK9EA9elFOUXKR9FtWFv6umIrCQUFOZTIseeX5vR/QBrQgIt

Steps to reproduce

Directly click the div button.

What is expected?

Two paths:

  • $event variable should be dropped for customized event.
  • keep $event but refer to an object with Event type

What is actually happening?

$event refers to the first parameter from $emit function call

System Info

No response

Any additional comments?

No response

@GYHHAHA GYHHAHA changed the title Inconsistent behavior between customized event and native DOM event on $event Unintentional $event value setting on customized event May 14, 2024
@quiteeasy
Copy link
Contributor

Probably, we should clarify in the Vue.js documentation for the v-on directive how inline function statements are parsed when using the $event variable. The format $event => ...function code might not be immediately clear to all users and could result in confusion or unintended behavior if not explained thoroughly.

@LinusBorg
Copy link
Member

keep $event but refer to an object with Event type

When we talk about custom events in Vue, we do not talk about CustomEvent instances from the DOM. We talk about Vue events, and this is how they work.

It's expected and documented behavior, so changing it would be a breaking change anyway.

I think the docs you link to do show at the end of the section that custom events also receive $event, and that it will refer to the event's payload

Bildschirmfoto 2024-05-14 um 19 45 51

@quiteeasy If you have a suggestion on how to make it clearer though, the docs team over at the docs repo would be happy about an issue or PR.

I'll close this as it's not a bug.

@github-actions github-actions bot locked and limited conversation to collaborators May 30, 2024
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

3 participants