首页 > Web开发 > 详细

[Vue] Lazy Load a Route by using the Dynamic Import in Vue.js

时间:2018-07-02 21:09:30      阅读:176      评论:0      收藏:0      [点我收藏+]

By default, vue-router doesn’t lazy load the routes unless you tell it to do it. Lazy loading of the non-critical routes is one of the points of the PRPL pattern.

This lesson will show you how you can use the dynamic import to lazy load non-critical routes.

 

When we using Vue dynamice import syntax:

const router = new VueRouter({
  routes: [
    { path: ‘/images‘, component: () => import(‘./components/Images‘) },
    { path: ‘/images/:id‘, component: () => import(‘./components/Details‘), props: true },
    { path: ‘/‘, redirect: ‘/images‘ }
  ]
})

 

To enable that, we need to install:

npm install babel-plugin-syntax-dynamic-import

.babelrc:

{
  "plugins": ["syntax-dynamic-import"]
}

 

[Vue] Lazy Load a Route by using the Dynamic Import in Vue.js

原文:https://www.cnblogs.com/Answer1215/p/9255751.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!