Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Vue load on demand to enhance user experience

2025-02-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Network Security >

Share

Shulou(Shulou.com)06/01 Report--

Vue official document Asynchronous component:

In large applications, we may need to split the application into several small modules and download them from the server on demand. To make things easier, Vue.js allows you to define a component as a factory function that parses the definition of the component dynamically. Vue.js triggers the factory function only when the component needs to render, and caches the results for later re-rendering.

The original picture and text is from h tt p / / www .cnb logs. Com/ Kumm y/p/525 47 54 .html

Vue loads related articles on demand:

1: htt p: / / c n. V u e j s. O rg / g u id e / co m p o ne n t s .ht ml# Asynchronous component

2: htt p: / / w eb p a ck. Gi t h ub. Io / d oc s / c o de-splitting.html

Today, we will give some practical project experience solutions for on-demand loading (that is, no request without loading):

Vue demand loading solution: require ([asynchronously loaded components], resolve)

Angular demand loading solution: $ocLazyLoad

Vue demand loading solution: require ([asynchronously loaded components], resolve)

It takes 2 steps to complete on-demand loading

The first step is to make configuration changes for webpack.js, as shown in the figure:

Step 2: make changes for router routing, mainly for component, as shown in the figure.

Step 3: execute the npm run build packaging command, and you can see that many small files of chunk are generated in the chunks folder, which is the vue component page, as shown in the figure:

Angular loads related articles on demand:

1: http://www.alloyteam.com/2016/03/es6-front-end-developers-will-have-to-know-the-top-ten-properties/

2: http://www.mamicode.com/info-detail-407754.html

Angular demand loading: $ocLazyLoad

It takes three steps to implement the on-demand loading solution.

Step 1: bower install oclazyload

Step 2: $ocLazyLoad encapsulation:

Step 3: ui-router routing configuration:

This scheme does this by loading files for template and controller on demand. You can see the effect by visiting the page at this time.

Gif demonstration of the effect:

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Network Security

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report