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. 請教使用PDO連接MSSQL數據庫插入是亂碼問題?2. node.js - nodejs開發中常用的連接mysql的庫3. Python爬蟲如何爬取span和span中間的內容并分別存入字典里?4. mysql - 分庫分表、分區、讀寫分離 這些都是用在什么場景下 ,會帶來哪些效率或者其他方面的好處5. 視頻文件不能播放,怎么辦?6. python - 數據與循環次數對應不上7. mysql - 把一個表中的數據count更新到另一個表里?8. 黑客 - Python模塊安全權限9. flask - python web中如何共享登錄狀態?10. mysql 查詢身份證號字段值有效的數據
