Add an emits option to examples that emit events #705
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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, usingemits
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
@
orv-on
will be included in the$attrs
unless it is listed in theemits
. 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 theemits
. 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 evenv-model
events will need to be included if a component has any other events. This was why I decided to includeemits
for all examples, even those usingv-model
.A few other notes:
foo
andbar
references have been changed.give-advice
toadvise
to dodge the problems around kebab-case vs camelCase (usingemits: ['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.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.app.mount('#emit-example-argument')
to one example. It was a complete example apart from that one line.