Documentation: https://github.com/hilongjw/vue-lazyload 1. Installationcnpm i vue-lazyload -S or npm i vue-lazyload -S 2. ExamplesImport configuration and other operations src/main.js import Vue from 'vue' import App from './App' import router from './router' //【1】Import lazy loading import VueLazyload from 'vue-lazyload' Vue.use(VueLazyload) //【1】Use lazy loading (choose 1 from the following sentence) //【1】Use lazy loading and enter the global configuration, so there is no need to configure error pictures, etc. where used (choose 1 from 2) // Vue.use(VueLazyload, { // preLoad: 1.3, // loading time // error: 'dist/error.png', // display this image if image error occurs // loading: 'dist/loading.gif', // display this image during loading // attempt: 1 // default number of images loaded // }) Vue.config.productionTip = false /* eslint-disable no-new */ new Vue({ el: '#app', router, template: '<App/>', components: App } }) Use lazy loading src/components/lazy.vue 【1】Define image error display, etc. (import images, if in js, must be required) <template> <div> <!--【2】Use lazy loading method v-lazy='xxx'--> <img v-lazy="imgUrl"/> <img v-lazy="imgObj" /> </div> </template> <script> export default{ name:"lazy", data(){ return { // [1] Define image error display, etc. (import images, if in js, must be required) imgObj: { preLoad: 1.3, //Loading time src: "http://www.wwtliu.com/sxtstu/blueberrypai/indexImg/banner1.jpg", //Real image error: require("../assets/error.jpg"), //If error occurs, display this image loading: require("../assets/loadingding.jpg"), //Display this image during loading attempt: 1, //Default number of images to load}, imgUrl:"http://www.wwtliu.com/sxtstu/blueberrypai/indexImg/banner2.jpg" //Only add one line, that is, the real picture} } } </script> <style></style> Effect: The image loaded when the image address is wrong. The loading process picture will be displayed during the loading process. This is the end of this article about Vue-lazyload image lazy loading. For more related Vue-lazyload image lazy loading content, please search 123WORDPRESS.COM's previous articles or continue to browse the following related articles. I hope everyone will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: How to quickly install Nginx in Linux
>>: SQL-based query statements
Convert code to image using html2canvas is a very...
This tutorial uses CentOS 7 64-bit. Allocate 2GB ...
Table of contents 1. What is an event? 2. How to ...
1. --cpu=<value> 1) Specify how much availa...
A simple cool effect achieved with CSS3 animation...
1. I purchased a VPS and CentOS system, and found...
Preface I recently wrote a small demo. Because I ...
Nowadays we often talk about Web2.0, so what is W...
Table of contents Overview Getting started with d...
Methods for changing passwords before MySQL 5.7: ...
This article example shares the specific code of ...
1.0 Redis persistence Redis is an in-memory datab...
Table of contents 1. When the mouse passes over t...
Get the Dockerfile from the Docker image docker h...
Preface Recently connected to mysql /usr/local/my...