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. react-native 启动Android项目失败2. python - 用ffmpeg采集视频,用terminate没法结束进程3. nginx - 关于vue项目部署到ngnix后出现的问题4. node.js - vue-resource,如何改变响应格式?5. phpadmin的数据库,可以设置自动变化时间的变量吗?就是不需要接收时间数据,自动变化6. gosts内容是空的7. javascript - js数组键名为何不能用变量?我想像PHP那样使用变量作为关联数组键名该怎么做?8. javascript - 手机点击input时,button会被顶上去?求解决!!!9. css - 关于HTML中width和height的疑问(这个提问的标题不好起)10. javascript - tab切换点击不同的按钮显示不同的内容

网公网安备