Example of implementing the skeleton screen of WeChat applet

Example of implementing the skeleton screen of WeChat applet

In order to optimize the user experience, the skeleton screen has always been the preferred display method by developers. It is a display method that occupies the first screen and will not make the viewer anxious due to long waiting time. The implementation of the skeleton screen in the mini program is relatively simple, but students who have never used it will inevitably go astray. Today I will share the implementation of the skeleton screen in the mini program.

What is a skeleton screen

The skeleton screen is a blank version of the page, which is usually roughly outlined by some gray blocks before the page is fully rendered. After the data is loaded, it is replaced with the real content. Usually in a mini program, we need to manually maintain the code of the skeleton screen. When the business changes, the skeleton screen code also needs to be adjusted. For the convenience of development, the developer tool provides the ability to automatically generate skeleton screen code.

How to generate skeleton screen in applet

WeChat developer tools can generate a skeleton screen for the current page. The tool entrance is located at the three dots in the lower right corner of the simulator panel.

Introduction method

The skeleton screen code is introduced through the mini program template. Taking the pages/index/index page as an example, the introduction method is as follows.

<!-- pages/index/index.wxml import template -->
<import src="index.skeleton.wxml"/>
<template is="skeleton" wx:if="{{loading}}" data="{{}}"/>
/* Import styles into pages/index/index.wxss*/
@import "index.skeleton.wxss";

Show and Hide

Same as ordinary templates, display and hiding are controlled by wx:if.
You can set delayed loading, or hide the skeleton screen after all data requests for the page are successful.
The lazy loading code is placed in the onLoad life cycle, the code is as follows:

   // Progressively load data and gradually hide loading
  progressiveLoad() {
    setTimeout(() => {
      this.setData({
        loading: false
      })
    }, 1000)
  },

  onLoad() {
    this.progressiveLoad() // Progressively load data and gradually hide loading
  }

Developers can also set the color and shape of text, images, and buttons as needed, and ignore or hide some page elements according to excludes, remove, hide, etc. to obtain better display effects. For specific configuration, see the official document of the skeleton screen

This is the end of this article about the implementation example of the WeChat applet skeleton screen. For more relevant applet skeleton screen content, please search for previous articles on 123WORDPRESS.COM 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 more elegant WeChat applet skeleton screen implementation
  • How to use skeleton screen in WeChat applet
  • Taro applet adds skeleton screen implementation code
  • How to build a skeleton screen for a mini program
  • Detailed record of the application and implementation steps of the WeChat applet skeleton screen

<<:  MySQL common statements for viewing transactions and locks

>>:  Detailed explanation of Docker common commands Study03

Blog    

Recommend

How to solve the abnormal error ERROR: 2002 in mysql

Recently, an error occurred while starting MySQL....

MySQL database implements OLTP benchmark test based on sysbench

Sysbench is an excellent benchmark tool that can ...

How to set MySQL foreign keys for beginners

Table of contents The role of foreign keys mysql ...

Div exceeds hidden text and hides the CSS code beyond the div part

Before hiding: After hiding: CSS: Copy code The co...

Examples of correct use of maps in WeChat mini programs

Table of contents Preface 1. Preparation 2. Actua...

Implementing a web calculator based on JavaScript

This article shares the specific code of JavaScri...

A brief discussion on Linux signal mechanism

Table of contents 1. Signal List 1.1. Real-time s...

Detailed explanation of MySQL information_schema database

1. Overview The information_schema database is th...

A quick review of CSS3 pseudo-class selectors

Preface If CSS is the basic skill of front-end de...

Detailed explanation of incompatible changes in rendering functions in Vue3

Table of contents Rendering API changes Render fu...

In-depth understanding of the role of Vuex

Table of contents Overview How to share data betw...

Interpretation of the module for load balancing using nginx

Table of contents Two modules for using nginx for...

Vue implements a movable floating button

This article example shares the specific code of ...