html5 - Vuejs服務端渲染同路由怎么適配移動和PC
問題描述
我現(xiàn)在的做法是,但這樣做前端js會直接報錯:
export function createRouter () {if (global.mobile) { return new Router({ mode: ’history’, scrollBehavior: () => ({ y: 0 }), routes: [{ path: ’/’, component: mobileIndex} ] }) }else { return new Router({ mode: ’history’, scrollBehavior: () => ({ y: 0 }), routes: [{ path: ’/’, component: index } ] }) }}
var is_mobile = function (req) { var ua = req.get(’User-Agent’) return /Android|webOS|iPhone|iPod|BlackBerry/i.test(ua); } console.log(’dasjka’,req) if (is_mobile(req) === true) { global.mobile = true }else { global.mobile = false }
我想知道一下業(yè)界同用的做法會是什么樣的?比如我寫好兩個頁面 a.vue和a-mobile.vue,怎么樣控制在同一個路由http://a.com下指向不同頁面文件
問題解答
回答1:使用iview或者v-strap
相關文章:
1. Docker for Mac 創(chuàng)建的dnsmasq容器連不上/不工作的問題2. docker安裝后出現(xiàn)Cannot connect to the Docker daemon.3. css - 關于border-image4. javascript - 怎么看網(wǎng)站用了什么技術框架?5. 關于Android權限的獲取問題,大家遇到過這樣的情況嘛?6. javascript - 編程,算法的問題7. javascript - 請教空白文本節(jié)點的問題8. PC 手機兼容的 編輯器9. javascript - 前端開發(fā) 本地靜態(tài)文件頻繁修改,預覽時的緩存怎么解決?10. 刷新頁面出現(xiàn)彈框
