vue-socket

想要在項目中登錄后傳參的的話,因為想要暴漏出來必須在main里面所有要么在mian里面 要么就在main的引入文件里面
1.在main 注冊然后暴漏現(xiàn)在要登錄但是在main 沒登陸也會暴漏
2.放路由攔截里面先讓路由加載完 然后再次攔截
3.代碼
var socketInited = false //防止重復(fù)加載
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調(diào)試,生產(chǎn)建議關(guān)閉
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()
})

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容