fffixed / vue-bus

Tiny simple central event bus plugin for Vue.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

vue-bus

awesome-vue license

A tiny simple central event bus plugin for Vue.js (requires Vue >= 2.0).

The plugin realise Non Parent-Child Communication.

(655 byte gzip)

Installation

Download and use with your build system

import VueBus from 'vue-bus'
// ... maybe ...
var VueBus = require('vue-bus')

// ...  and  ...

Vue.use(VueBus)

Or just include it with a script tag

<script src="/vue-bus.js"></script>

Usage

direct way:

// in component A's method
this.$bus.$emit('my-event', 1)

// in component B's created hook
this.$bus.$on('my-event', function(arg) {
  // ...
})

//And don't forget to use "this.$bus.$off" to remove unnecessary listeners.

magic way:

// in component A's method
this.$bus=['my-event', 1]

// in component B create $bus option
methods: { /* ... */ },
$bus: {
  'my-event': function(arg) {
    // ...
  }
}

License

MIT

Copyright (c) 2017 fffixed

About

Tiny simple central event bus plugin for Vue.js

License:MIT License


Languages

Language:JavaScript 100.0%