vue webpack 懶載入三種方式
阿新 • • 發佈:2018-11-26
const router = new Router({
routes: [
{
path: '/index',
component: (resolve) => {
require(['../components/index/index'], resolve) // 這裡是你的模組 不用import去引入了
}
}
]
})
const hyh = resolve => { import ('@/components/index/hyh').then(modul =>{ resolve(module) }) }
const router = new Router({
routes: [
{
path: '/hyh',
component: hyh,
name: 'hyh'
}
]
})
// r就是resolve
const list = r => require.ensure([], () => r(require('../components/list/list')), 'list');
// 路由也是正常的寫法 這種是官方推薦的寫的 按模組劃分懶載入
const router = new Router({
routes: [
{
path: '/list/blog',
component: list,
name: 'blog'
}
]
})