Skip to content

Cweili/vue-option-events

Folders and files

NameName
Last commit message
Last commit date
Dec 21, 2021
Jan 29, 2019
May 11, 2020
May 18, 2019
May 18, 2019
May 12, 2018
Dec 10, 2021
Jan 29, 2019
Dec 23, 2021
Feb 27, 2019
Jan 29, 2019
Dec 21, 2021
Jul 22, 2024
Jan 29, 2019
Feb 15, 2019

Repository files navigation

vue-option-events

npm bundle size npm downloads license

github build 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
});