Vue-Router 的懒加载如何实现
非懒加载:
import List from '@/components/list.vue' const router = new VueRouter({ routes: [ { path: '/list', component: List } ] })
懒加载:
1.使用箭头函数+import动态加载
const List = () => import('@/components/list.vue') const router = new VueRouter({ routes: [ { path: '/list', component: List } ] })
2.使用箭头函数+require动态加载
const router = new Router({ routes: [ { path: '/list', component: resolve => require(['@/components/list'], resolve) } ] })