Get the App
SLTechnology News&Howtos  ›  Development  › 

How does WeChat Mini Programs realize self-defined toast

Shulou Source: shulou.com Published: 2022-05-31 21:19:40 10月03日 Update

This article mainly introduces "WeChat Mini Programs how to achieve custom toast" related knowledge, editor through the actual case to show you the operation process, the method of operation is simple and fast, practical, I hope that this "WeChat Mini Programs how to achieve custom toast" article can help you solve the problem.

Wechat officially defaults to toast.

Toast is the most common. Almost every App has such special effects. Let's first take a look at the toast effect that comes with Mini Program.

Wechat comes with toast:

Js file:

Wx.showToast ({title: 'success', icon: 'success', duration: 2000})

It's super easy to use, but there are several problems with the official Mini Program:

Only success and loading icon can be displayed.

And icon cannot be removed.

Duration up to 10 seconds

II. Custom toast

Our most common toast is at the bottom, and the height is relatively small.

Let's first look at the effect:

It seems simple, but it is not easy to implement. How to achieve:

1) create a common template template file for toast, because toast is required for each page

{{title}}

2) JS has the following main uses

Core code:

Let pages = getCurrentPages (); let curPage = pages [pages.length-1]

This code is the core, getCurrentPages (). Length-1 indicates that you can get the page of the current page, and only when you get the page can you bind the data of the current page to toast through page.setData.

Core code:

Let animation = wx.createAnimation (); animation.opacity (1). Step ()

This code has a slow animation effect when toast disappears.

This is the end of the introduction of "how to achieve custom toast by WeChat Mini Programs". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Programs code effects core knowledge pages official common files industries different practical maximum slow successful content a few questions animation only practicality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Shulou Technology MariaDB Xiaomi Shulou Information