1.1.0 • Published 3 years ago
socket.io-vuewrapper v1.1.0
socket.io-vuewrapper
Other versions support outdated dependencies, no longer receive updates or do not respond to pull requests, which is why socket.io-vuewrapper was created.
Parts of this REPO were used, so thanks to David Gurshumov and Metin Seylan.
🚀 Installation
npm i socket.io-vuewrapper --save
Example
src/main.js
import { createApp } from 'vue';
import App from './App.vue';
import VueSocketIO from 'socket.io-vuewrapper';
const vSocket = new VueSocketIO({
    debug: true,
    connection: 'http://localhost:8000'
});
createApp(App).use(vSocket).mount('#app')| 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 | 
src/App.vue
...
<script>
export default {
  mounted() {
    // Check if you are connected to the server
    if (this.$socket.connected) {
      // Send an object to the connected server
      this.$socket.emit('test', { message: "example" });
    }
  },
  sockets: {
    // Listen for the custom `test` event
    test: function(msg) {
      console.log(msg);
    }
  }
}
</script>
...