event emit on

Estimated reading time: 1 minute

event emit on

    1. plugins/eventBus.js
import Vue from 'vue'

const eventBus = {}

eventBus.install = (Vue) => {
Vue.prototype.$bus = new Vue()
}

Vue.use(eventBus)
    1. register plugin
plugins: [
  '~/plugins/eventBus'
],
  • usage
// event emit
this.$bus.$emit('activity');
// event on
this.$bus.$on('activity',()=>{
  console.log("here is kamal")
})

emit

// Input changed
this.$root.$emit('removeposition', { something: 'yes' })

// Component 2
this.$root.$on('removeposition', filter => { })

event handling child component

  • nested.vue
<template>
  <nuxt-child @something="handle_something" />
</template>
  • nested/index.vue
<template>
  <button @click="$emit('something!')" >something</button>
</template>