[Vuejs]-Get data of Vue component from outside vue

0👍

Create a simple plugin to wrap the socket and send/receive messages. When you create the components, install the plugin – Vue.use(MySocketPlugin) – and then in each component it will be available as the name you give it – i.e. this.$mySocketPlugin.

this.$mySocketPlugin.onmessage('some-message', function (payload) {
     // do the thing with payload
})

this.$mySocketPlugin.send('some-other-message', data)    

Alternatively, create a global mixin with the necessary methods for sending and receiving data. Both approaches are really similar, just a matter of which you prefer.

Leave a comment