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. mac連接阿里云docker集群,已經卡了2天了,求問?2. ddos - apache日志很多其它網址,什么情況?3. 上傳圖片老是失敗是什么原因?SAE_TMP_PATH.后面跟的路徑在哪看4. javascript - 關于jquery的ajax post數據的問題5. 前端 - 我有一個建站程序,但是多個文件夾下的HTML模板代碼沒有進行縮進格式化,請問用什么軟件可以批量格式化一下代碼?6. android-studio - Win10下修改Windows用戶文件夾名user,導致Android Studio報錯無法使用7. phpstudy pro小皮面板經常報這個nginx: [emerg] CreateFile【急】8. thinkphp5.1學習時遇到session問題9. angular.js - angular 路由為什么一直請求css和js文件10. javascript - setTimeout的延遲時間,是從什么時間段開始算起的?
