html5 - Vuejs服務端渲染同路由怎么適配移動和PC
問題描述
我現在的做法是,但這樣做前端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 }
我想知道一下業界同用的做法會是什么樣的?比如我寫好兩個頁面 a.vue和a-mobile.vue,怎么樣控制在同一個路由http://a.com下指向不同頁面文件
問題解答
回答1:使用iview或者v-strap
相關文章:
1. javascript - 關于<a>元素與<input>元素的JS事件運行問題2. mysql - 記得以前在哪里看過一個估算時間的網站3. python - 有什么好的可以收集貨幣基金的資源?4. python - 啟動Eric6時報錯:’qscintilla_zh_CN’ could not be loaded5. css3 - 我想要背景長度變化,而文字不移動,要怎么修改呢6. MySQL中的enum類型有什么優點?7. css3 - 純css實現點擊特效8. javascript - vue 怎么渲染自定義組件9. javascript - 同步方式寫異步到底指什么?10. android下css3動畫非常卡,GPU也不差啊
