Registry / web-framework / vue-events

vue-events

JSON →
library3.1.0jsnpmunverified

vue-events is a Vue.js plugin designed to simplify global event handling within applications built with Vue 1.x or Vue 2.x. It extends the Vue prototype with a `$events` object, which acts as a global event bus, abstracting away the underlying Vue instance's `$emit`, `$on`, and `$off` methods. The package provides several aliases for these core methods, such as `fire`/`emit` for `$emit`, `listen`/`on` for `$on`, and `remove`/`off` for `$off`, aiming for a more semantic API. The current stable version is 3.1.0, published in 2017. This package is not compatible with Vue 3.x, as Vue 3 removed the core event emitter API (`$on`, `$off`, `$once`) that this plugin relies upon. As such, while it served its purpose for earlier Vue versions, it is no longer actively maintained or suitable for modern Vue 3 development.

npm install vue-events
INSTALL
IMPORT
SIG · VUE-EVENTS
V
vue-events
web-frameworkjavascriptv3.1.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–226 runs
build_error
glibc
node 18–226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

VueEvents
✓ import VueEvents from 'vue-events'
✗ const VueEvents = require('vue-events')
This plugin is typically installed using `Vue.use(VueEvents)`. The `require()` pattern is for older CommonJS environments or when Vue is globally available (e.g., via `window.Vue`).
Vue
✓ import Vue from 'vue'
✗ import { Vue } from 'vue'
Required to install the plugin via `Vue.use()`. Vue's default export is the constructor.
$events
✓ this.$events.fire('myEvent', payload)
✗ this.$emit('myEvent', payload) (when intending to use the global bus)
`$events` is added to the Vue prototype after plugin installation; it's not directly imported. It acts as the global event bus.

This quickstart demonstrates how to install `vue-events` and use its `$events.on` and `$events.fire` methods to communicate between parts of a Vue 2.x application.

import Vue from 'vue'; import VueEvents from 'vue-events'; // Install the plugin Vue.use(VueEvents); // Create a root Vue instance new Vue({ el: '#app', data() { return { message: 'Hello from Vue Events!' }; }, mounted() { // Listen for an event this.$events.on('exampleEvent', (data) => { console.log('Received exampleEvent:', data); this.message = `Event received: ${data.detail}`; }); // Fire an event after a short delay setTimeout(() => { this.$events.fire('exampleEvent', { detail: 'Data from emitter!' }); }, 1000); }, beforeDestroy() { // It's good practice to remove listeners to prevent memory leaks this.$events.off('exampleEvent'); }, template: ` <div> <h1>Vue Events Demo</h1> <p>{{ message }}</p> <button @click="triggerAnotherEvent">Trigger Another Event</button> </div> `, methods: { triggerAnotherEvent() { this.$events.emit('anotherEvent', { source: 'button' }); } } }); // A separate component or instance can also listen or emit new Vue({ mounted() { this.$events.listen('anotherEvent', (data) => { console.log('Another event caught!', data); }); } }).$mount(document.createElement('div')); // Mount without an element to just make it active.
Debug
Known issues
breakingThis package is fundamentally incompatible with Vue 3.x. Vue 3 removed the `$on`, `$off`, and `$once` instance methods from Vue instances, which `vue-events` relies upon for its global event bus functionality. Attempting to use `vue-events` in a Vue 3 application will result in runtime errors.
fix
For Vue 3, consider using alternative event emitter libraries like `mitt` or `tiny-emitter`, or adopt more idiomatic Vue 3 communication patterns such as props/emits, provide/inject, or global state management with Pinia/Vuex.
affects: >=3.0.0 of Vue
deprecatedThe global event bus pattern, while convenient for simple cases, is largely discouraged in modern Vue 2.x and especially Vue 3.x applications. It can lead to hard-to-trace event flows, hidden dependencies, and maintainability issues as applications grow.
fix
Prefer explicit component communication via props and `$emit` for parent-child, `provide`/`inject` for descendant communication, or dedicated state management solutions like Vuex/Pinia for global state.
affects: >=2.0.0 of Vue
gotchaThe package provides multiple aliases for its core methods (`fire`, `emit`, `$emit` for emitting; `listen`, `on`, `$on` for listening; `remove`, `off`, `$off` for removing). While intended for flexibility, this can lead to inconsistent code styles within a team and confusion about which alias to use.
fix
Establish a team convention for which aliases to consistently use, e.g., sticking to the Vue-native `$emit`, `$on`, `$off` names.
affects: all
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading '$events')
The `vue-events` plugin was not correctly installed via `Vue.use(VueEvents)` before creating Vue instances, or the import path for `VueEvents` was incorrect.
fix
Ensure `import VueEvents from 'vue-events'; Vue.use(VueEvents);` is executed *before* any Vue instances that attempt to use `$events` are created. Verify the import path is correct.
Property '$events' does not exist on type 'Vue'.
Using TypeScript without proper type declaration merging for the `vue-events` plugin, or the plugin was not installed globally onto the Vue prototype.
fix
Ensure the plugin is installed with `Vue.use(VueEvents)`. If using TypeScript, you might need to add a declaration file to augment the `Vue` instance type, typically by declaring a module `vue-events` and adding `$events` to `Vue.prototype`.
This plugin cannot be installed because it has already been installed.
Attempting to call `Vue.use(VueEvents)` multiple times in the application lifecycle.
fix
`Vue.use()` should typically be called only once at the application's entry point (e.g., `main.ts` or `main.js`). Remove redundant calls to `Vue.use(VueEvents)`.
Upgrade
Version history
3.1.0latest on npm
Audit
Dependencies
vuerequiredCore dependency for the plugin to function and extend Vue's prototype. Compatible with Vue 1.x and 2.x.
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
vue-events — npm install vue-events · libregistry