vue-socket

想要在项目中登录后传参的的话,因为想要暴漏出来必须在main里面所有要么在mian里面 要么就在main的引入文件里面
1.在main 注册然后暴漏现在要登录但是在main 没登陆也会暴漏
2.放路由拦截里面先让路由加载完 然后再次拦截
3.代码
var socketInited = false //防止重复加载
router.beforeEach((to, from, next) => {
if (!socketInited) {
let userId = store.getters.user.userId
console.log('userId', userId);
let socketOptions = {
autoConnect: false, // 是否自动连接
query: room=yimai&namespace=yimai_namespace&userId=${userId},
transports: ['websocket'],
}
// 注册
Vue.use(
new VueSocketIO({
debug: true, // debug调试,生产建议关闭
connection: SocketIO(process.env.NODE_ENV == 'development' ? "192.168.1.14:9099" : "https://ym.cfsoft.top", socketOptions),
})
)
// vuex: {
// store,
// actionPrefix: 'SOCKET_',
// mutationPrefix: 'SOCKET_'
// },
// options: { query: merCode=555555&userId=1dda7781a7204bb2a2107a5b029e63ed }

//   }))
socketInited = true

}
next()
})

你可能感兴趣的:(vue-socket)