Use the older version of the package for Vue 2.x.
Note that this release will no longer release updates. I'm going to focus development on supporting Vue 3.x features.
npm install vue-simple-websocket@0.0.3 --save
In the Vue app entry file main.js
import VueSimpleWebSocket from 'vue-simple-websocket'
Vue.use(VueSimpleWebSocket, 'wss://echo.websocket.org')
In the Vue app entry file main.js
Vue.use(VueSimpleWebSocket, 'wss://echo.websocket.org', {
reconnectEnabled: true,
reconnectInterval: 5000 // time to reconnect in milliseconds
})
You will then have a $socketClient
instance in your Vue instance.
Follow the instructions in the Readme to send and receive messages.