In the WeChat applet, showToast is an API used to display message prompt boxes. The specific usage is as follows:
wx.showToast({
title: '提示信息',
icon: 'success', // 可选值:'success', 'loading', 或 'none'
duration: 2000, // 持续时间,单位为毫秒,默认值为 1500
success: function() {
// 显示成功后的回调函数
},
fail: function() {
// 显示失败后的回调函数
},
complete: function() {
// 页面显示完成后的回调函数
}
})
Among them, success
, fail
, complete
are callback functions, which will be called when the corresponding event is triggered.
For example, if you need to perform some operations after the message prompt box is displayed successfully, you can achieve this by passing in the callback function showToast
in the configuration object success
.
Sample code looks like this:
wx.showToast({
title: '操作成功',
icon: 'success',
duration: 2000,
success: function() {
// 在消息提示框显示成功后执行的操作
console.log('操作完成!')
}
})
In this example, when the message prompt box is displayed, 'Operation Completed!' will be printed on the console. ' Information.