vue实现路由懒加载

未懒加载的路由

import Rou from '@/views/rou.vue'
const router = new VueRouter({
  routes: [
    { path: '/rou', component: Rou }
  ]
})

 

懒加载

方案一:

const Rou = () => import('@/views/rou.vue')
const router = new VueRouter({
  routes: [
    { path: '/rou', component: Rou }
  ]
})

 

 

方案二

// 省去import
const router = new Router({
  routes: [
   {
     path: '/rou',
   name: 'Rou' component: (resolve)
=> {require(['@/views/rou.vue'], resolve) }
  }
 ]
})

 

posted @ 2021-07-26 09:32  我的世界蹦擦擦  Views(79)  Comments(0Edit  收藏  举报