方式一,用声明变量加箭头函数方式引入
一般这种更常用
const List = () => import('@/components/list.vue')
const router = new VueRouter({
routes: [
{ path: '/list',
component: List
}
]
})
方式二
const router = new Router({
routes: [
{
path: '/list',
component: (resolve) => {
require(['@/components/list'], resolve)
}
}
]
})
方式三
// r就是resolve
const List = r => require.ensure([], () => r(require('@/components/list')), 'list');
// 这种是官方推荐的写的 按模块划分懒加载
const router = new Router({
routes: [
{
path: '/list',
component: List,
name: 'list'
}
]
}))
vue 路由懒加载
最新推荐文章于 2024-05-04 06:29:34 发布