Skip to content

/guide/components/events.md #2300

Open
Open
@freemedom

Description

@freemedom

Although optional, it is recommended to define all emitted events in order to better document how a component should work. It also allows Vue to exclude known listeners from [fallthrough attributes](/guide/components/attrs#v-on-listener-inheritance), avoiding edge cases caused by DOM events manually dispatched by 3rd party code.

avoiding edge cases caused by DOM events manually dispatched by 3rd party code


vuejs/core#27

The problem is that these same listeners can also be triggered by custom events - in the above example, both a native click event and a custom one emitted by this.$emit('click') in the child will trigger the parent's foo handler. This may lead to unwanted behavior.

I don't quite understand why edge cases are caused by 3rd party code manually dispatch event?
If declare the events in emits option, should the events only manually dispatched by code be the target's behavior?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions