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

Add an emits option to examples that emit events #705

Merged
merged 1 commit into from
Nov 21, 2020

Conversation

skirtles-code
Copy link
Contributor

Note: There is a CodePen at the bottom of list.md that should be updated to match the code in this PR.

Closes #702.

I have added an emits option to examples that $emit events. This isn't strictly necessary for any of these examples, as they function correctly without it. However, using emits is encouraged elsewhere in the documentation and omitting it can cause problems in situations that are very similar to those in the documentation.

An event listener registered with @ or v-on will be included in the $attrs unless it is listed in the emits. In most cases this does no harm but it does result in a listener being added to the root DOM node of the component. So long as the event name doesn't coincide with a DOM event name this is largely harmless, though wasteful.

Events created by v-model are slightly different. They are not included in the $attrs even if they are omitted from the emits. No listener is added to the DOM node.

However, if a component uses the emits option then it has to list all events, otherwise there'll be a warning logged. So even v-model events will need to be included if a component has any other events. This was why I decided to include emits for all examples, even those using v-model.

A few other notes:

  1. Some foo and bar references have been changed.
  2. I renamed the event give-advice to advise to dodge the problems around kebab-case vs camelCase (using emits: ['give-advice'] didn't actually work correctly). That's a problem that needs addressing properly and I didn't want to get into it here.
  3. I chopped const app = Vue.createApp({}) in a few places where it didn't seem necessary. Note that the other examples on that page weren't using it.
  4. I added app.mount('#emit-example-argument') to one example. It was a complete example apart from that one line.

Copy link
Member

@NataliaTepluhina NataliaTepluhina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@skirtles-code thank you for these changes! CodePen updated as well 👍🏻

@NataliaTepluhina NataliaTepluhina merged commit e554cd6 into vuejs:master Nov 21, 2020
nick-lai pushed a commit to nick-lai/docs-next that referenced this pull request Dec 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Why v-model on the сustom component throw a warning without emits?
2 participants