您好,登錄后才能下訂單哦!
這篇文章主要講解了“vue路由懶加載如何實現(xiàn)”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“vue路由懶加載如何實現(xiàn)”吧!
1.使用import方法實現(xiàn)路由懶加載
const Home = () => import(/* webpackChunkName: 'ImportFuncDemo' */ '@/components/home.vue')
const Index = () => import(/* webpackChunkName: 'ImportFuncDemo' */ '@/components/index.vue')
const About = () => import(/* webpackChunkName: 'ImportFuncDemo' */ '@/components/about.vue')
const router = new VueRouter({
routes: [
{ path: '/home', component: Home },
{ path: '/index', component: Index },
{ path: '/about', component: About }
]
})
2.使用require.ensure()方法實現(xiàn)路由懶加載
{
path: '/home',
name: 'home',
component: r => require.ensure([], () => r(require('@/components/home')), 'demo')
}, {
path: '/index',
name: 'Index',
component: r => require.ensure([], () => r(require('@/components/index')), 'demo')
}, {
path: '/about',
name: 'about',
component: r => require.ensure([], () => r(require('@/components/about')), 'demo-01')
}
3.使用vue異步組件實現(xiàn)路由懶加載
{
path: '/home',
name: 'home',
component: resolve => require(['@/components/home'],resolve)
},{
path: '/index',
name: 'Index',
component: resolve => require(['@/components/index'],resolve)
},{
path: '/about',
name: 'about',
component: resolve => require(['@/components/about'],resolve)
}
感謝各位的閱讀,以上就是“vue路由懶加載如何實現(xiàn)”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對vue路由懶加載如何實現(xiàn)這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!
免責聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。