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 - 父级设置了相对定位。子元素设置了绝对定位。子元素中包含了浮动的table,这个时候高度不能自适应。2. docker容器呢SSH为什么连不通呢?3. docker images显示的镜像过多,狗眼被亮瞎了,怎么办?4. node.js - npm init无法一直回车。到version就卡主不动了5. docker api 开发的端口怎么获取?6. docker网络端口映射,没有方便点的操作方法么?7. golang - 用IDE看docker源码时的小问题8. dockerfile - 为什么docker容器启动不了?9. debian - docker依赖的aufs-tools源码哪里可以找到啊?10. docker start -a dockername 老是卡住,什么情况?
