1. 程式人生 > 實用技巧 >socket套接字

socket套接字

//在 router/index.js 中有兩個頁面。

exportdefaultnewRouter({ mode:'history', routes: [ { path:'', redirect:'/pc_index' }, { path:"/pc_index",// pc端首頁 name: PcIndex, component: PcIndex }, { path:'/m_index',// 手機端首頁 name: MIndex, component: MIndex } ] }); 在 App.vue 的 mounted 方法中對設定進行判斷,如下: //App.vue mounted() { if(this._isMobile()) {
alert("手機端"); this.$router.replace('/m_index'); }else{ alert("pc端"); this.$router.replace('/pc_index'); } } methods:{ _isMobile(){ letflag=navigator.userAgent.match( /(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|WindowsPhone)/i ); returnflag; }, },