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. angular.js - 如何控制ngrepeat输出的个数2. 网页爬虫 - python requests爬虫,如何post payload3. node.js - 问个问题 Uncaught (in promise)4. python爬虫 - scrapy使用redis的时候,redis需要进行一些设置吗?5. mysql5.7就没有官方性质的详细配置文件吗?求大神告知6. angular.js - angular指令中的scope属性中用&获取父作用域函数的问题7. html - 这种错位的时间轴怎么布局,然后用css实现?8. CSS3 flex 如何让高度不等的同排等高?9. python3.x - python3.5.2安装时make报错求助10. javascript - 关于ajax请求问题!

网公网安备