[Vuejs]-How to add event listeners to Vue socket cluster client in a method?

0👍

The right solution would be to

  1. Create a vue.use for the connection with autoConnect: false below import VueSocketCluster from ‘vue-socket-cluster’
> Vue.use(VueSocketCluster, {
>         connections: [{
>           name: 'SeoScan', // Each connection object must have a name and the name must be unique in the array
>           hostname: 'localhost',
>           secure: false,
>           port: 5128,
>           rejectUnauthorized: false,
>           autoConnect: false
>         }]
>       });
  1. then, add in your components (here HelloWorld.vue) the event listeners under export default

    SeoScanEvents: {
    connect: function (data) {
    console.log(‘socket connected’)
    console.log(data)
    },
    random (data) {
    console.log(data)
    }
    }

  2. In the method submit1 rather than calling the method connect from the root, call the method that will start the connection: this.$SeoScanClient.connect();

Leave a comment