Closed travbus closed 2 years ago
While I never got this vue-socket.io to work i did get socket.io-client to work
this is in my user module
import type { UserModule } from '~/types'
import { io } from 'socket.io-client';
const options = {
//path: '/test/',
transports: ['websocket'],
forceNew: true,
auth: {
token: "TOKEN 123"
}
}
export const install: UserModule = ({ app }) => {
const socket = io('http://localhost:3000',options);
app.config.globalProperties.$socket = socket;
app.provide('socket', socket);
}
this is in my component
<script setup lang="ts">
import { ref,inject } from 'vue';
const socket:any = inject('socket');
socket.on("testListener", (data:any) => {
console.log(data);
});
const test = () =>{
socket.emit("test", 5);
}
Frustrating. Getting back into coding and a vue 3 type script newbie. Very hard to get things working it seems I'm thinking of ditching it at this point. Here is my issue. I do have the latest dependency files from this repo installed. Still getting this error. I have no other code in the app other then these photos. I did not modify main.ts from boiler plate. I just added a new module file. Willing to donate some dollars to anybody with a solution.
Uncaught (in promise) TypeError: Cannot set properties of undefined (setting '$socket')