首页  >  问答  >  正文

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下指向不同页面文件

大家讲道理大家讲道理2662 天前1028

全部回复(1)我来回复

  • typecho

    typecho2017-07-06 10:36:58

    使用iview或者v-strap

    回复
    0
  • 取消回复