vue3项目使用vue-socket报Uncaught TypeError: Cannot set properties of undefined (setting ‘$socket’),是由于vue-socket版本的问题,目前vue-socket只支持vue2.0版本,如果想继续使用需要对源码进行一些修改。打开node_modules/vue-socket.io/dist/vue-socket.js,将
t.prototype.$socket=this.io,t.prototype.$vueSocketIo=this
改为
t.config.globalProperties.$socket=this.io,t.config.globalProperties.$vueSocketIo = this
如下图: