Introduction to the use of the image preloading component wxapp-img-loader in WeChat applet

不言
Release: 2018-10-18 15:22:32
forward
5739 people have browsed it

This article brings you an introduction to the use of the image preloading component wxapp-img-loader in the WeChat applet. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. help.

Since the WeChat applet does not provide JS objects like Image, it is more troublesome to preload images. The wxapp-img-loader custom component can implement image preloading in the WeChat applet. Function.

Use

1. Download the wxapp-img-loader project source code (https://github.com/o2team/wxa...), and transfer img- Copy the loader directory to your project

2. Add the following code to the WXML file of the page and introduce the component template

<import></import>
<template></template>
Copy after login

3. Introduce the component script into the JS file of the page

const ImgLoader = require('../../img-loader/img-loader.js')
Copy after login

4. Instantiate an ImgLoader object and pass in this (current Page object). The second parameter is optional and is the callback method for the default image loading completion.

this.imgLoader = new ImgLoader(this)
Copy after login

5. Call ImgLoader The load method of the instance loads the image. The first parameter is the image link, and the second parameter is optional and is the callback method when the image is loaded. The first parameter of the callback method when the image loading is completed is the error message (null if the loading is successful), and the second parameter is the image information (Object type, including src, width and height).

this.imgLoader.load(imgUrlOriginal, (err, data) => {    console.log('图片加载完成', err, data.src, data.width, data.height)
})
Copy after login

wxapp-img-loader component can load a single image or multiple images.

running result:
Introduction to the use of the image preloading component wxapp-img-loader in WeChat applet

Introduction to the use of the image preloading component wxapp-img-loader in WeChat applet

Other

wxapp-img-loader project address: https://github.com/o2team/wxa...

The above is the detailed content of Introduction to the use of the image preloading component wxapp-img-loader in WeChat applet. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!