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. html5 - 只用CSS如何實現input框的寬度隨框里輸入的內容長短自動適應?2. 人工智能 - python 機器學習 醫療數據 怎么學3. mysql - 分庫分表、分區、讀寫分離 這些都是用在什么場景下 ,會帶來哪些效率或者其他方面的好處4. Python爬蟲如何爬取span和span中間的內容并分別存入字典里?5. javascript - 關于css絕對定位在ios瀏覽器被橡皮筋遮擋的問題6. c++ - 請問MySQL_Connection::isReadOnly 怎么解決?7. css3 - 微信前端頁面遇到的transition過渡動畫的bug8. python - beautifulsoup獲取網頁內容的問題9. python - Django內使用filter過濾時間,只認年份不認月份是怎么回事?10. python - 能通過CAN控制一部普通的家用轎車嗎?
