A tiny simple central event bus plugin for Vue.js (requires Vue >= 2.0).
The plugin realise Non Parent-Child Communication.
(655 byte gzip)
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>
✨
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) {
// ...
}
}
Copyright (c) 2017 fffixed