Summary of vue project optimization methods
This time I will bring you a summary of vue project optimization methods. What are the precautions for vue project optimization? The following is a practical case, let’s take a look.
Image optimization
1. Image size optimization, some images use WebP (webp compatibility needs to be considered)
Online Generate, such as Zhitu and Youpaiyun
gulp generation, gulp-webp or gulp-imageisux
canvas generation
2. Reduce image requests and use sprite images
to generate online: sprites Generator, Tencent’s gopng, spriteme
Code generation: gulp.spritesmith or sass compass
Lazy loading of images or components
Use vue-lazyload component or some other component
vue-lazyload address: https://www.npmjs.com/package/vue-lazyload
Image lazy loading: v-lazy or use v-lazy-container to contain a picture group
// 引入一张图片 <img v-lazy="//domain.com/img1.jpg"> // 引入一组图片 <p v-lazy-container="{ selector: 'img', error: 'xxx.jpg', loading: 'xxx.jpg' }"> <img src="//domain.com/img1.jpg"> <img src="//domain.com/img2.jpg"> <img src="//domain.com/img3.jpg"> </p>
Component lazy loading
Vue.use(VueLazyload, { lazyComponent: true }); <lazy-component> <img class="mini-cover" :src="img.src" width="100%" height="400"> </lazy-component>
Image preloading
Quickly display pictures
Usage scenario: In a component that views pictures, when constantly flipping through the pictures on the next page, getting data from the server and then displaying the pictures will cause the pictures to load slowly. In this case When displaying new data, you can preload the image first. After the image is loaded, fill the image into the corresponding position
Three-party plug-in lazy loading (loading on demand)
js files are generally loaded synchronously, and placing them in the page will block the loading of the main js files.
Usage scenarios: When some projects must introduce files such as jquery, introducing these files inside the component will block page rendering to a certain extent, so it is dynamically loaded through specific events (click or pop-up window) JS files such as jquery can quickly display the main page.
Asynchronous loading of pages, how to prevent components from overlapping
When multiple vue components are loaded and the components are rendered through server-side data, multiple components will first overlap and then separate. Situation
Three options
#When the section displayed on the page is fixed and the height of the content is not easy to change, it can be set outside the component in advance A fixed height that displays like adding content to a frame. When the page content is not fixed, in order to reduce the problem of overlapping components during asynchronous loading, you can set other components to be displayed on the first screen when the data of a certain component is loaded, and displayed through v-show.
When the page is fixed as a whole, you can add a skeleton to the page to prevent the page from flickering. For specific implementation, please refer to http://www.jb51.net/article/130505.htm
Server-side rendering page. For some pages with fixed data and few changes, you can consider passing Server-side rendering will display the page in a short time, providing a better user experience.
Reduce the size of imported external files
When the project introduces some ElementUI content, configure the .babelrc file by introducing babel-plugin-component, so that Partial components can be introduced to reduce the size of the component.
Routing lazy loading
But when using vue-router, webpack will package all components in a js file, which will cause the file to be very large, thus It will affect the loading of the homepage. The best way is to package other routes into different js files, and then load the corresponding js files when switching routes.
resolve => require([URL], resolve), good support
() => system.import(URL), already available on webpack2 official website The statement will be gradually abolished. It is not recommended to use
() => import(URL). It is recommended by the webpack2 official website. It belongs to the es7 category and needs to be used with babel’s syntax-dynamic-import plug-in.
I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website!
Recommended reading:
Summary of three ways to dynamically load JS files
Summary of cross-domain methods for js to support post requests
The above is the detailed content of Summary of vue project optimization methods. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Tomato Novel is a very popular novel reading software. We often have new novels and comics to read in Tomato Novel. Every novel and comic is very interesting. Many friends also want to write novels. Earn pocket money and edit the content of the novel you want to write into text. So how do we write the novel in it? My friends don’t know, so let’s go to this site together. Let’s take some time to look at an introduction to how to write a novel. Share the Tomato novel tutorial on how to write a novel. 1. First open the Tomato free novel app on your mobile phone and click on Personal Center - Writer Center. 2. Jump to the Tomato Writer Assistant page - click on Create a new book at the end of the novel.

Unfortunately, people often delete certain contacts accidentally for some reasons. WeChat is a widely used social software. To help users solve this problem, this article will introduce how to retrieve deleted contacts in a simple way. 1. Understand the WeChat contact deletion mechanism. This provides us with the possibility to retrieve deleted contacts. The contact deletion mechanism in WeChat removes them from the address book, but does not delete them completely. 2. Use WeChat’s built-in “Contact Book Recovery” function. WeChat provides “Contact Book Recovery” to save time and energy. Users can quickly retrieve previously deleted contacts through this function. 3. Enter the WeChat settings page and click the lower right corner, open the WeChat application "Me" and click the settings icon in the upper right corner to enter the settings page.

Mobile games have become an integral part of people's lives with the development of technology. It has attracted the attention of many players with its cute dragon egg image and interesting hatching process, and one of the games that has attracted much attention is the mobile version of Dragon Egg. To help players better cultivate and grow their own dragons in the game, this article will introduce to you how to hatch dragon eggs in the mobile version. 1. Choose the appropriate type of dragon egg. Players need to carefully choose the type of dragon egg that they like and suit themselves, based on the different types of dragon egg attributes and abilities provided in the game. 2. Upgrade the level of the incubation machine. Players need to improve the level of the incubation machine by completing tasks and collecting props. The level of the incubation machine determines the hatching speed and hatching success rate. 3. Collect the resources required for hatching. Players need to be in the game

Setting font size has become an important personalization requirement as mobile phones become an important tool in people's daily lives. In order to meet the needs of different users, this article will introduce how to improve the mobile phone use experience and adjust the font size of the mobile phone through simple operations. Why do you need to adjust the font size of your mobile phone - Adjusting the font size can make the text clearer and easier to read - Suitable for the reading needs of users of different ages - Convenient for users with poor vision to use the font size setting function of the mobile phone system - How to enter the system settings interface - In Find and enter the "Display" option in the settings interface - find the "Font Size" option and adjust it. Adjust the font size with a third-party application - download and install an application that supports font size adjustment - open the application and enter the relevant settings interface - according to the individual

In today's society, mobile phones have become an indispensable part of our lives. As an important tool for our daily communication, work, and life, WeChat is often used. However, it may be necessary to separate two WeChat accounts when handling different transactions, which requires the mobile phone to support logging in to two WeChat accounts at the same time. As a well-known domestic brand, Huawei mobile phones are used by many people. So what is the method to open two WeChat accounts on Huawei mobile phones? Let’s reveal the secret of this method. First of all, you need to use two WeChat accounts at the same time on your Huawei mobile phone. The easiest way is to

The difference between Go language methods and functions lies in their association with structures: methods are associated with structures and are used to operate structure data or methods; functions are independent of types and are used to perform general operations.

Mobile phone film has become one of the indispensable accessories with the popularity of smartphones. To extend its service life, choose a suitable mobile phone film to protect the mobile phone screen. To help readers choose the most suitable mobile phone film for themselves, this article will introduce several key points and techniques for purchasing mobile phone film. Understand the materials and types of mobile phone films: PET film, TPU, etc. Mobile phone films are made of a variety of materials, including tempered glass. PET film is relatively soft, tempered glass film has good scratch resistance, and TPU has good shock-proof performance. It can be decided based on personal preference and needs when choosing. Consider the degree of screen protection. Different types of mobile phone films have different degrees of screen protection. PET film mainly plays an anti-scratch role, while tempered glass film has better drop resistance. You can choose to have better

Time complexity measures the execution time of an algorithm relative to the size of the input. Tips for reducing the time complexity of C++ programs include: choosing appropriate containers (such as vector, list) to optimize data storage and management. Utilize efficient algorithms such as quick sort to reduce computation time. Eliminate multiple operations to reduce double counting. Use conditional branches to avoid unnecessary calculations. Optimize linear search by using faster algorithms such as binary search.
