Vue-Socket.io is a socket.io integration for Vuejs, easy to use, supporting Vuex and component level socket consumer managements
Demo
are you looking for old documentation? it's here
🚀 Installation
npm install vue-socket.io --save
Using Connection String
Vuerouterstore
Using socket.io-client Instance
const options = path: '/my-app/' ; //Options object to pass into SocketIOVue;routerstore
Parameters | Type's | Default | Required | Description |
---|---|---|---|---|
debug | Boolean | false |
Optional | Enable logging for debug |
connection | String/Socket.io-client | null |
Required | Websocket server url or socket.io-client instance |
vuex.store | Vuex | null |
Optional | Vuex store instance |
vuex.actionPrefix | String | null |
Optional | Prefix for emitting server side vuex actions |
vuex.mutationPrefix | String | null |
Optional | Prefix for emitting server side vuex mutations |
🌈 Component Level Usage
If you want to listen socket events from component side, you need to add `sockets` object in Vue component, and every function will start to listen events, depends on object key
sockets:{console}{console}methods:{// $socket is socket.io-client instancethis$socket}
Dynamic Listeners
If you need consuming events dynamically in runtime, you can use `subscribe` and `unsubscribe` methods in Vue component
thissockets;thissockets;
🏆 Vuex Integration
When you set store parameter in installation, `Vue-Socket.io` will start sending events to Vuex store. If you set both prefix for vuex, you can use `actions` and `mutations` at the same time. But, best way to use is just `actions`
VueVuex