Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gocanto/vuemit
The smallest Vue.js events handler.
https://github.com/gocanto/vuemit
events javascript vuejs
Last synced: 9 days ago
JSON representation
The smallest Vue.js events handler.
- Host: GitHub
- URL: https://github.com/gocanto/vuemit
- Owner: gocanto
- License: mit
- Created: 2017-01-31T20:12:35.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2023-04-18T04:21:32.000Z (over 1 year ago)
- Last Synced: 2024-10-18T20:46:53.214Z (21 days ago)
- Topics: events, javascript, vuejs
- Language: JavaScript
- Homepage:
- Size: 606 KB
- Stars: 143
- Watchers: 5
- Forks: 11
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-vue - vuemit - 处理VueJS事件 (实用库)
- awesome-github-vue - vuemit - 处理VueJS事件 (实用库)
- awesome-github-vue - vuemit - 处理VueJS事件 (实用库)
- awesome - vuemit - 处理VueJS事件 (实用库)
README
# Vuemit
Vuemit is a tiny library to work with events on Vue.js. Its aim is to keeping simple the fact of sharing information between any number of components.
# Installation
```js
npm install vuemit --save
```# Gettings started
Require the library within your entry point or your bootstrap file.
```js
window.Vuemit = require('vuemit');
```Now you will have a global ***Vuemit*** variable which you can use anywhere in your app.
# Usage
- all the methods take the same props as the [Original Events](https://vuejs.org/v2/api/#Instance-Methods-Events), except for the events-names which can be an array.
| Vue | Vuemit | Description |
|--------------|------------------------------|-----------------------------------------------------------------------------------|
| this.$emit() | Vuemit.fire() | ***Fire an event/s :*** takes 2 arguments ('event-name', (optional) data object) |
| this.$on() | Vuemit.listen() | ***Listen for an event/s :*** takes 2 arguments ('event-name', callback) |
| this.$once() | Vuemit.listenOnce() | ***Listen once to an event/s :*** takes 2 arguments ('event-name', callback) |
| this.$off() | Vuemit.remove() | ***Remove listeners for an event/s:*** takes 2 arguments ('event-name', callback) |
| this.$off() | Vuemit.removeListenersFrom() | ***Remove listeners from an event/s:*** takes 1 arguments ('event-name') |
| this.$off() | Vuemit.removeAll() | ***Remove all event listeners:*** takes no arguments |- Vue started to support events array from **v2.2.0+** except `$emit` & `$once` but with Vuemit you can use events-names as an array with all the methods except `removeAll()` which takes no arguments.
```js
// fire multiple events with a shared payload
Vuemit.fire(['event1','event2'], {some: data})// listen once to multiple events with a shared callback
Vuemit.listenOnce(['other-event1', 'other-event2'], ()=>{
// do something ex."refresh localStorage"
})
```# Contributing
Please feel free to fork this package and contribute by submitting a pull request to enhance the functionalities.
# License
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
# How can I thank you?
Why not star the github repo? Why not share the link for this repository on Twitter? Spread the word!Don't forget to [follow me on twitter](https://twitter.com/gocanto)!
Thanks!
Gustavo Ocanto.
[email protected]