probil / vue-socket.io-extended

:v::zap: Socket.io bindings for Vue.js and Vuex (inspired by Vue-Socket.io)
MIT License
629 stars 38 forks source link

Exporting sockets object into a class/plugin #440

Open rostgoat opened 4 years ago

rostgoat commented 4 years ago

Rather having everything sit in main.ts, is there a way to export sockets into a class of it's own?

Having something like this can get rather cumbersome..

new Vue({
    sockets: {
      connect() {
        this.$socket.client.emit("connected", {
          title: "cod"
        });
        this.$socket.client.on("connected", (data: string) =>
          console.log(data)
        );
      }
    },

However when I try to use this.$socket in src/plugins/index.ts I get Property '$socket' does not exist on type 'NextClietPlugin'

Can you recommend anything @probil ?

probil commented 4 years ago

Hey @rostgoat Could please provide me the class you've tried in src/plugins/index.ts? Without seeing usage it's hard to figure out the problem and why it didn't work