I'm making a vue 3 app, I'm starting with a web connection test visiting the official web guide, but I don't reach the goal to test it through the socket-client.io package. How do I do this?. This is what I've done about it, I need to make a socket to a external website (There is no need to have a backend part to make this possible or a sample):
I put the Socket.ts at the root of the project.
import { reactive } from 'vue' import { io } from 'socket.io-client' export const state = reactive({ connected: false }) export const socket = io('https://www.google.com') socket.on('connect', () => { state.connected = true }) socket.on('disconnect', () => { state.connected = false })
then I'm using it in my component:
<script setup lang="ts"> import { state } from '../Socket' import { socket } from '../Socket' const connected = computed(() => { return state.connected }) onMounted(async () => { console.log socket.connect() }) </script> <template> <p> {{ connected}} </p> </template>