vue-option-events

2.0.1 • Public • Published

vue-option-events

npm bundle size npm downloads license

github travis coverage

Bring Vue.js 1 events option and $emit to Vue.js 2.

Install

npm install vue-option-events --save

Basic Usage

Install plugin

import Vue from 'vue';
import vueOptionEvents from 'vue-option-events';
 
Vue.use(vueOptionEvents);

Set events option

Component A

new Vue({
  methods: {
    show(hiMessage) {
      console.log(hiMessage);
    }
  },
 
  events: {
    hello(helloMessage) {
      console.log(helloMessage);
    },
    hi: 'show'
  }
});

Component B

new Vue({
  methods: {
    send() {
      this.$emit('hello', 'world');
      this.$emit('hi', 'world');
    }
  }
});

Use as global event bus

new Vue({
  methods: {
    send() {
      this.$event.$emit('hello', 'world');
    }
  }
});

Emit events from any where

import eventBus from 'vue-option-events';
 
eventBus.$emit('hello', 'world');

Options

Vue.use(vueOptionEvents, {
  keepAlive: false
});

Package Sidebar

Install

npm i vue-option-events

Weekly Downloads

8

Version

2.0.1

License

MIT

Unpacked Size

21.4 kB

Total Files

11

Last publish

Collaborators

  • cweili