Registry / http-networking / vue-echo

vue-echo

JSON →
library1.0.2jsnpmunverified

Vue-Echo provides a plugin for integrating Laravel Echo, a JavaScript library for real-time event broadcasting, into Vue.js applications. This package is specifically designed for Vue 2 applications, injecting an Echo instance into all Vue components via `this.$echo` and offering declarative channel subscription options within component definitions. The current stable version is 1.0.2, with its last known update fixing a minor bug. The package's release cadence appears to have slowed considerably, likely due to its focus on Vue 2 while Vue 3 is the current major version. It differentiates itself by simplifying the integration of Laravel Echo's real-time features with Vue's component lifecycle and reactive data patterns, offering both global and component-specific event handling mechanisms.

npm install vue-echo
INSTALL
IMPORT
SIG · VUE-ECHO
V
vue-echo
http-networkingjavascriptv1.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

VueEcho
import VueEcho from 'vue-echo';
import { VueEcho } from 'vue-echo';
VueEcho is the default export for the plugin. It is passed to `Vue.use()` for plugin registration.
$echo
this.$echo.private('channel').listen('Event', callback);
The Laravel Echo instance is automatically injected into all Vue instances as `this.$echo` after plugin registration.
channel/echo component options
new Vue({ channel: 'my-channel', echo: { 'MyEvent': (payload, vm) => { /* ... */ } } });
For declarative, component-level subscriptions, define `channel` and `echo` options directly on your Vue instance or component.

This quickstart demonstrates how to initialize `vue-echo` with Laravel Echo configuration (Pusher example), and then how to subscribe to public and private channels using both the `this.$echo` instance and the declarative `channel` and `echo` component options.

import Vue from 'vue'; import VueEcho from 'vue-echo'; import Echo from 'laravel-echo'; // Assuming laravel-echo is installed // Option 1: Initialize VueEcho directly with configuration Vue.use(VueEcho, { broadcaster: 'pusher', key: 'YOUR_PUSHER_APP_KEY', // Replace with your Pusher App Key or environment variable cluster: 'mt1', // Optional, replace with your cluster forceTLS: true // Optional }); // Option 2: Pass an existing Laravel Echo instance /* const echoInstance = new Echo({ broadcaster: 'pusher', key: 'YOUR_PUSHER_APP_KEY', cluster: 'mt1', forceTLS: true }); Vue.use(VueEcho, echoInstance); */ const app = new Vue({ el: '#app', data: { messages: [] }, // Declarative channel subscription within the component channel: 'public.chat', echo: { 'ChatMessageSent': (payload, vm) => { console.log('New message received via declarative config:', payload.message); vm.messages.push(payload.message); } }, mounted() { console.log('VueEcho instance available:', this.$echo); // Manual subscription via this.$echo this.$echo.private('private.notifications.user.1') .listen('NewNotification', (notification) => { console.log('New private notification:', notification); }); // Manually listen on the component's channel if defined if (this.channel) { this.channel.listen('AnotherEvent', (payload) => { console.log('Another event on component channel:', payload); }); } }, template: ` <div> <h1>Vue-Echo Example</h1> <p>Check console for real-time events.</p> <h2>Public Chat Messages:</h2> <ul> <li v-for="(msg, index) in messages" :key="index">{{ msg }}</li> </ul> </div> ` });
Debug
Known issues
breakingVersion 1.0.0 introduced `vm` as a second parameter to locally registered event callbacks (i.e., callbacks defined in the `echo` option of a Vue component). This was added to provide direct access to the Vue instance, improving context handling. Code written for versions prior to 1.0.0 where `this` was used within these callbacks might need adjustment if `this` was expected to refer to the Vue instance.
fix
Update event handlers in the `echo` component option to accept `(payload, vm)` and use `vm` instead of `this` for accessing the Vue instance context.
affects: <1.0.0
gotchaThis library is designed for Vue 2. It will not work with Vue 3 due to fundamental changes in Vue's plugin system and reactivity model. Attempting to use `vue-echo` in a Vue 3 project will result in errors.
fix
For Vue 3 projects, you must find an alternative solution or integrate Laravel Echo manually via a custom plugin or composable. This package is not compatible with Vue 3.
affects: >=0.1.0
gotchaWhen defining event listeners within the `echo` option of a Vue component, the `this` context inside the callback does not directly refer to the Vue instance by default (prior to v1.0.0, or if not using the `vm` parameter in v1.0.0+).
fix
Since v1.0.0, event callbacks receive the Vue instance as a second parameter (`(payload, vm) => { vm.someData = payload; }`). Always use this `vm` parameter to safely access component data and methods. For manual listeners via `this.$echo.listen()`, arrow functions `() => {}` are recommended to retain the lexical `this` context of the `mounted` hook or method where they are defined.
affects: >=0.1.0
gotchaThe `channel` option on a Vue instance (`this.channel`) only references the instance's specifically subscribed channel when using the declarative `channel` option. For other channels, use the global `this.$echo` instance.
fix
Understand that `this.channel` is a convenience for the single channel defined in the component's `channel` option. For dynamic subscriptions or managing multiple channels, always use the `this.$echo` instance (e.g., `this.$echo.channel('another-channel')`).
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'private') at VueComponent.mounted
The `vue-echo` plugin or `laravel-echo` instance was not properly initialized or registered with Vue.
fix
Ensure `Vue.use(VueEcho, { broadcaster: 'pusher', key: '...' });` is called before creating your root Vue instance, and that all necessary `laravel-echo` dependencies (like `pusher-js` or `socket.io-client`) are installed and configured correctly.
TypeError: this.$echo is undefined
The `vue-echo` plugin has not been registered with Vue, or the component is being accessed before the plugin has fully initialized.
fix
Verify that `Vue.use(VueEcho, ...)` is invoked correctly and that `vue-echo` and `laravel-echo` are installed (`npm install vue-echo laravel-echo pusher-js`). For server-side rendering (SSR), ensure `this.$echo` access is guarded against non-browser environments.
Webpack compilation error: Cannot find module 'vue-echo'
The `vue-echo` package is not installed as a project dependency.
fix
Run `npm install vue-echo laravel-echo --save` or `yarn add vue-echo laravel-echo` to add the package to your project.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
laravel-echorequiredCore dependency for real-time broadcasting functionality; vue-echo wraps and integrates it.
Agent activity
24 hits · last 30 days
node
20
Amazon
1
OpenAI (training)
1
Resources
vue-echo — npm install vue-echo · libregistry