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-echoVerified import paths — ran on the pinned version, not inferred.
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.
Update event handlers in the `echo` component option to accept `(payload, vm)` and use `vm` instead of `this` for accessing the Vue instance context.
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.
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.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')`).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.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.
Run `npm install vue-echo laravel-echo --save` or `yarn add vue-echo laravel-echo` to add the package to your project.