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) } ] })

 

 
 
posted @ 2023-08-20 14:43  胡猿外  阅读(24)  评论(0编辑  收藏  举报