Answer the question
In order to leave comments, you need to log in
How to get rid of duplicate socket subscriptions? How to use socket.io in SPA?
A simple Vue application. Two routes: subscription occurs on one route
beforeMount () {
socket.emit('subscribeToTimer', 1000)
socket.on('timer', timestamp => {
this.timestamp = timestamp
this.countEvents++
})
}
App.vue
so as not to duplicate it again in each component.beforeMount () {
console.log('socket work')
socket.on('connect', () => {
console.log('CONNECTION STATUS:', socket.connected)
console.log('SOCKET:', socket.id)
})
socket.on('disconnect', () => {
console.log('DISCONNECTION STATUS:', socket.disconnected)
})
socket.open()
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question