socket.client.js 368 B

123456789101112131415161718
  1. // Nuxt 3: plugins/socket.client.js
  2. import io from 'socket.io-client'
  3. export default defineNuxtPlugin(() => {
  4. const socket = io('http://localhost:3000')
  5. socket.on("message", (arg) => {
  6. console.log(arg); // "world"
  7. });
  8. return {
  9. provide: {
  10. socket: socket
  11. }
  12. }
  13. })
  14. export const socket = io('http://localhost:3000')