Vue-Socket.io is a socket.io integration for Vuejs, easy to use, supporting Vuex and component level socket consumer managements
Demoare you looking for old documentation? it's here
ð InstallationUsing Connection Stringnpm install vue-socket.io --save
Using socket.io-client Instanceimport Vue from 'vue'
import store from './store'
import App from './App.vue'
import VueSocketIO from 'vue-socket.io'
Â
Vue.use(new VueSocketIO({
    debug: true,
    connection: 'http://metinseylan.com:1992',
    vuex: {
        store,
        actionPrefix: 'SOCKET_',
        mutationPrefix: 'SOCKET_'
    },
    options: { path: "/my-app/" }Â
}))
Â
new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
Parameters Type's Default Required Description debug Booleanimport Vue from 'vue'
import store from './store'
import App from './App.vue'
import VueSocketIO from 'vue-socket.io'
Â
const options = { path: '/my-app/' };Â
Â
Vue.use(new VueSocketIO({
    debug: true,
    connection: SocketIO('http://metinseylan.com:1992', options),Â
    vuex: {
      store,
      actionPrefix: "SOCKET_",
      mutationPrefix: "SOCKET_"
    }
  })
);
Â
new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app')
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
Dynamic Listenersnew Vue({
    sockets: {
        connect: function () {
            console.log('socket connected')
        },
        customEmit: function (data) {
            console.log('this method was fired by the socket server. eg: io.emit("customEmit", data)')
        }
    },
    methods: {
        clickButton: function (data) {
           Â
            this.$socket.emit('emit_method', data)
        }
    }
})
If you need consuming events dynamically in runtime, you can use `subscribe` and `unsubscribe` methods in Vue component
ð Vuex Integrationthis.sockets.subscribe('EVENT_NAME', (data) => {
    this.msg = data.message;
});
Â
this.sockets.unsubscribe('EVENT_NAME');
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`
Stargazers over timeimport Vue from 'vue'
import Vuex from 'vuex'
Â
Vue.use(Vuex)
Â
export default new Vuex.Store({
    state: {},
    mutations: {
        "<MUTATION_PREFIX><EVENT_NAME>"() {
           Â
        }
    },
    actions: {
        "<ACTION_PREFIX><EVENT_NAME>"() {
           Â
        }
    }
})
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4