Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shooterrao/vue-plugin-event-bus
🌱 A vue2.x eventBus plugin,easy to use eventBus
https://github.com/shooterrao/vue-plugin-event-bus
Last synced: 6 days ago
JSON representation
🌱 A vue2.x eventBus plugin,easy to use eventBus
- Host: GitHub
- URL: https://github.com/shooterrao/vue-plugin-event-bus
- Owner: shooterRao
- License: mit
- Created: 2020-06-11T15:27:19.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-08-12T14:48:50.000Z (over 3 years ago)
- Last Synced: 2024-10-28T16:58:51.739Z (17 days ago)
- Language: TypeScript
- Homepage:
- Size: 39.1 KB
- Stars: 8
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# vue-plugin-event-bus
Lightweight eventBus solution, easy to use eventBus in vue2.x
## Feature
- Mapping relationship between events and components
- Auto $off events## Installing
use npm
```
npm install vue-plugin-event-bus
```use yarn
```
yarn add vue-plugin-event-bus
```## Usage
```js
import Vue from "vue";
import VueEventBus from "vue-plugin-event-bus";Vue.use(VueEventBus);
// now you can use $eventBus directly in a vue component
// in vue component lifecycle hooks...
{
created() {
this.$eventBus.on('xxx', function callback() {}, this); // you should pass in the current vue instance
// if you don't pass the current instance,like use this.$on(xxx),you should manual remove eventHandler...
// so,I strongly recommend you pass 'this'(current vue instance)
// because it can auto remove eventHandler when component is destroyed
}
}// in another vue component
{
methods: {
test() {
this.$eventBus.emit('xxx', ...);
}
},
}
```