0👍
Simply put, $emit
register an event in a component, and then you can listen to this event in other places wherever the component is used.
Say if you have a Child.vue
and somewhere in this component, you did:
.$emit('some-event')
Then you can listen to this event when Child
component is reused, for instance in another component SomeComponent.vue
, you can do:
<template>
<child @some-event="doSomething"></child>
</template>
So here the event is triggered in the child component, but you decide what to do in the parent component with doSomething
. Hope this makes sense!
0👍
The wording on the docs might create confusion to some people.
Maybe something in the lines of: “Makes the vm
current instance dispatch an event” would be clearer?
In the end it is just a classic pub/sub pattern: your component instance emits / dispatches / fires an event, and other components (typically the parent one) listen / subscribe (v-on
/ @
) to that event.