[Vuejs]-How to use vue-socket.io + vuex for realtime?

1👍

It’s quite unclear what you’re trying to do, but if i understand correctly, you want the “created” event to be emitted to all sockets, after one socket triggers the “create” event. If so:

 socket.on('create',(name)=> {
        io.of('/').emit('created', {name})            
    })

Problem is, that for some reason you’re registering the “connection” event within some “create” function, which doesn’t seem to make much sense. Your io.on(‘connection’) needs to be registered once, in some high level module, and within its scope you need to register all specific events for the connecting socket. I don’t have your full code, so i can’t say, but this is something you need to look at.

đŸ‘€i.brod

0👍

I found the answer myself. The problem is that i was using

**socket.emit('postVoted', {updatedPost})**

Where socket.emit Means that the updated data its comming to the user who created that action, but changing that event to:

**io.sockets.emit**

This way every use gets the updated data.

Clearly im not expert with socketio,any good course about sockets? thanks

NOTE : I have seriues doubts about using 2 .on(‘connection’) methods, any advice on how to module this?

đŸ‘€Alex Hunter

Leave a comment