Socket.io client and server module for Nuxt
npm i nuxt-socket@1 should help revert any breaking changes in your code.
Record<string, string> have been deprecated in favor of string-only entries, which are easier to work with.nuxt-socket-io dependency to your projectnpm i nuxt-socket-io
npm i nuxt-socket-io@2
nuxt-socket-io to the modules section of nuxt.config.js{
modules: [
'nuxt-socket-io',
],
io: {
// module options
sockets: [{
name: 'main',
url: 'http://localhost:3000'
}]
}
}
{
mounted() {
this.socket = this.$nuxtSocket({
channel: '/index'
})
/* Listen for events: */
this.socket
.on('someEvent', (msg, cb) => {
/* Handle event */
})
},
methods: {
method1() {
/* Emit events */
this.socket.emit('method1', {
hello: 'world'
}, (resp) => {
/* Handle response, if any */
})
}
}
}
But WAIT! There's so much more you can do!! Check out the documentation:
There you will see:
yarn install or npm installyarn dev or npm run dev