-
Notifications
You must be signed in to change notification settings - Fork 4.6k
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
Events as Props: more details added #2594
Conversation
✅ Deploy Preview for vuejs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
|
||
If no handler is defined, attempting to use `props.onSomeEvent()` as an emitter, will result in a console error. | ||
|
||
When passing an event handler as a prop, and kebab-case is used (ie: `:on-some-event`), the handler won't be interpreted when using the `emit('someEvent')` emitter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've reported the issue vuejs/core#9812 and the PR vuejs/core#9813
The intention of that part of the docs it to show you can still pass props as events, because that's been used in more advanced usages and not not a clear behaviour for some users, I've added the documentation of it as an FYI. I recommend do not dwell to much on it because is not a feature that regular users should be using, the behaviour does not have a spec and might change in the future, while some of the libraries that rely on that behaviour have resources to make changes if the spec is needed, the same is not expected from users. @NataliaTepluhina if that section will cause confusion on the community, might be better to remove it completely to prevent confusion. Edit: The main goal for adding that to the docs is to explain possibly <script setup>
import Comp from './Comp.vue';
const obj = {
onClick: () => {
// this can be called as an `$emit('click')`
console.log('clicked me')
}
}
</script>
<template>
<Comp v-bind="obj" />
</template> |
IMHO, if is not in the specs, as is not recommended and because some caveats it might be better to avoid Event as Props content. Maybe a “Vue Hacks” section can be added to the guide for this kind of features that are not in specification. |
I removed the whole section for now. The idea of Vue hacks/workarounds is really nice, we should look into it 👍🏻 |
I wrote different cases In the Playground to understand the Events as Props
Description of Problem
1- It was missing a dot and new line
2- as the former will pass only handle the property based listener sentence was not clear for me
3- (either
@event
or:on-event
) is using:kebab-case
instead of:camelCase
, and it could lend into an issue when using$emit
(explained in the new warning sentences).Proposed Solution
1- Dot and new line added
2- I've tried to rewrite the sentence, maybe you can suggest a better one.
3-
:on-event
replaced with:onEvent
Additional Information
I've found more warings to add