[Vue] Lazy Load a Route by using the Dynamic Import in Vue.js
Posted Answer1215
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[Vue] Lazy Load a Route by using the Dynamic Import in Vue.js相关的知识,希望对你有一定的参考价值。
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的主要内容,如果未能解决你的问题,请参考以下文章
[Javascript] IntersectionObserver -- Lazy Load Images on a Website
SQLAlchemy lazy load和eager load
SAP Spartacus 的延迟加载 Lazy load 设计原理
使用 hibernate.enable_lazy_load_no_trans 解决 Hibernate Lazy-Init 问题