Skip to content

fffixed/vue-bus

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

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

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published