123456789101112131415161718 |
- // Nuxt 3: plugins/socket.client.js
- import io from 'socket.io-client'
- export default defineNuxtPlugin(() => {
- const socket = io('http://localhost:3000')
- socket.on("message", (arg) => {
- console.log(arg); // "world"
- });
- return {
- provide: {
- socket: socket
- }
- }
- })
- export const socket = io('http://localhost:3000')
|