[Vuejs]-VueJS Emiting events and passing data along the way

0👍

For parent and child components, you can do it in an easier way.

The following is just a demo.

Parent

<child-component v-on:increment="increaseCount"></child-component>

export default {
  name: 'parent-component',
  data () {
    return {
      count: 0
    }
  },
  methods: {
    increaseCount: () => this.count++
  }
}

Child

<template>
  <button @click="incrementCount"></button>
</template>

export default {
  name: 'child-component',
  methods: {
    incrementCount: () => this.$emit('increment')
  }
}

Leave a comment