Detailed explanation of Vue lazyload picture lazy loading example

Detailed explanation of Vue lazyload picture lazy loading example

Documentation: https://github.com/hilongjw/vue-lazyload

1. Installation

cnpm i vue-lazyload -S
or npm i vue-lazyload -S

2. Examples

Import 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)
【2】Use lazy loading method v-lazy='xxx'

<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:
  • A brief introduction to using lazy loading of images in Vue. A detailed guide to the vue-lazyload plugin
  • Detailed explanation of Vue custom image lazy loading instruction v-lazyload
  • Summary of vue-lazyload usage (recommended)
  • Example explanation of vue-lazyload image delayed loading plug-in
  • Vue implements lazy loading of images

<<:  How to quickly install Nginx in Linux

>>:  SQL-based query statements

Recommend

MySQL solution for creating horizontal histogram

Preface Histogram is a basic statistical informat...

Tutorial on how to quickly deploy clickhouse using docker-compose

ClickHouse is an open source column-oriented DBMS...

HTML form tag usage learning tutorial

Forms in HTML can be used to collect various type...

Sample code for automatic web page refresh and automatic jump

Automatic web page refresh: Add the following code...

How to create a trigger in MySQL

This article example shares the specific code for...

CSS uses BEM naming convention practice

When you see a class, what information do you wan...

What is the file mysql-bin.000001 in mysql? Can it be deleted?

After installing MySQL using ports, I found that ...

An article to help you understand Js inheritance and prototype chain

Table of contents Inheritance and prototype chain...

Detailed explanation of viewing and setting file permissions on Mac

Preface To modify file permissions in the termina...

Detailed explanation of how to copy and backup docker container data

Here we take the Jenkins container as an example ...

How does JS understand data URLs?

Table of contents Overview Getting started with d...

Detailed explanation of table return and index coverage examples in MySQL

Table of contents Index Type Index structure Nonc...

Detailed explanation of how to pass password to ssh/scp command in bash script

Install SSHPASS For most recent operating systems...

Detailed introduction of Chrome developer tools-timeline

1. Overview Users expect the web applications the...

In-depth explanation of MySQL learning engine, explain and permissions

engine Introduction Innodb engine The Innodb engi...