(十四)router按需加载组件

2018-10-15  本文已影响0人  我拥抱着我的未来

按需加载组件

import Vue from 'vue'
import Router from 'vue-router'
import Home from '@/pages/home/Home'
import City from '@/pages/city/City'
import Detail from '@/pages/Detail/Detail'
Vue.use(Router)

export default new Router({
  routes: [{
    path: '/',
    name: 'Home',
    component: Home
  },
  {
    path: '/city',
    name: 'City',
    component: City
  },
  {
    path: '/detail/:id',
    name: 'Detail',
    component: Detail
  }
  ],
  // 自定义路由切换时页面如何滚动
  scrollBehavior (to, from, savedPosition) {
    return {
      x: 0,
      y: 0
    }
  }
})

import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

export default new Router({
  routes: [{
    path: '/',
    name: 'Home',
    component: () =>
        import('@/pages/home/Home')

  },
  {
    path: '/city',
    name: 'City',
    component: () =>
        import('@/pages/city/City')

  },
  {
    path: '/detail/:id',
    name: 'Detail',
    component: () =>
        import('@/pages/Detail/Detail')

  }
  ],
  // 自定义路由切换时页面如何滚动
  scrollBehavior (to, from, savedPosition) {
    return {
      x: 0,
      y: 0
    }
  }
})

上一篇下一篇

猜你喜欢

热点阅读