Get the App
SLTechnology News&Howtos  ›  Development  › 

Example Analysis of lazy loading of lazyload Images in Vue

Shulou Source: shulou.com Published: 2022-06-02 05:37:40 10月04日 Update

This article mainly introduces the example analysis of lazy loading of lazyload pictures in Vue. The article is very detailed and has a certain reference value. Interested friends must finish reading it!

1. Install cnpm I vue-lazyload-S or npm I vue-lazyload-S2. Example

Import configuration and other operations such as src/main.js

Import Vue from 'vue'import App from'. / App'import router from'. / router'// [1] Import lazy load import VueLazyload from 'vue-lazyload'Vue.use (VueLazyload) / / [1] lazy load use (and the following sentence 2 choose 1) / / [1] lazy load use, and enter the global configuration There is no need to configure error pictures, etc. (2 choose 1) / / Vue.use (VueLazyload, {/ / preLoad: 1.3, / / load time / / error: 'dist/error.png', / / the picture incorrectly displays this picture / / loading:' dist/loading.gif' / / the loading process displays this figure / / attempt: 1 / / default number of loaded pages / /}) Vue.config.productionTip = false / * eslint-disable no-new * / new Vue ({el:'# app', router, template:', components: {App}})

Load src/components/lazy.vue using laziness

[1] define picture error display, etc. (introduce a picture, if it is in js. Must require come in)

[2] use lazy loading to write vmurlazywritten xxx'

Export default {name: "lazy", data () {return {/ / [1] defines the wrong display of pictures, etc. (introduce pictures, if in js. Must require in) imgObj: {preLoad: 1.3, / / load time src: "http://www.wwtliu.com/sxtstu/blueberrypai/indexImg/banner1.jpg",// real picture error: require (".. / assets/error.jpg "), / / if this picture is displayed incorrectly, loading: require (".. / assets/loadding.jpg ") / / the loading process displays this figure attempt: 1, / / default number of loaded pages}, imgUrl: "http://www.wwtliu.com/sxtstu/blueberrypai/indexImg/banner2.jpg" / / add only one entry That is, the real picture}}

Effect: the picture loaded when the address of the picture is wrong. The loading process displays a picture of the loading process.

The above is all the contents of the article "sample Analysis of lazy loading of lazyload pictures in Vue". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Tags: Picture error process configuration example analysis content time is in article no value global interest writing address example guy partner effect Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Xiaomi macOS Linux Apple Microsoft