My VueJS 2 application contains a parent component and a child component. The parent passes a prop called items
to the child.
When the user clicks on a button in the child component it emits a refresh
event like this:
$emit('refresh', category.id)
I'd like to listen to this event in the parent component and, if the event is received, trigger a method, e.g. alert()
.
As far as I have understood the `` the v-on
listener can be attached to e.g. a button or else. The problem is that my parent component does not have something like a button for this.
To make things clearer here's what I'm thinking of:
- Parent component is loaded. It calls a
getData()
function which result is passed as a prop to the child component. - The user clicks a button in the child component.
- The child component triggers an event.
- The parent component again calls
getData()
and updated the prop passed to the child.