A lightweight Vue 3 plugin for integrating WebSocket connections using the Composition API. Current stable version 2.2.0 (released 2023-09). Provides both a plugin (Vue3Websocket) and composable (useWebSocket) for reactive WebSocket communication. Key differentiator: designed specifically for Vue 3's Composition API with automatic lifecycle management and reactive state. Unlike generic WebSocket wrappers, it handles reconnection, message handling as reactive data, and integrates seamlessly with Vue's reactivity system. Released under MIT, maintained by a solo developer with monthly updates. Supports TypeScript out of the box.
npm install vue3-websocketNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Registers the WebSocket plugin globally with reconnection and heartbeat, then uses the composable to send messages and reactively receive data.
Use named imports: import { Vue3Websocket, useWebSocket } from 'vue3-websocket'Always register the plugin with app.use() before using useWebSocket.
Use 'reconnectionDelay' instead of 'reconnectInterval'.
Pass url as a separate property: { url: '...', options: { ... } }Ensure the composable is called inside a component that is a descendant of the app root.
Add app.use(Vue3Websocket, { url: 'ws://yourserver' }) in main.js.Use import { useWebSocket } from 'vue3-websocket'.Ensure URL starts with 'ws://' or 'wss://' and is correctly formatted.
Check that the WebSocket is open before calling send; wait for status.value === 'OPEN'.