[Vuejs]-Vuejs emit method from component to root

0👍

You will need to listen to the event using on:

<item-edit v-for="item in items" :item="item" v-on:increment="increment">
</item-edit>

Now, the v-on:increment will call the method increment of that component.

increment() {
  score += 1
}

So now, how to tell the child component to emit the event?

Well, you will just emit the event from the method where you wish.

methodToEmit() {
  this.$emit('increment')
}

Your question, how will I call methodToEmit without button?

You may call it right after toggle method is applied:

toggle() {
  // do other stuff
  this.methodToEmit()
}

Or, you may bind a hidden input element and bind the method to call methodToEmit method in mounted hook.

Leave a comment