用户操作得到即时反馈,这是很好的用户体验,所以我们经常会使用提示框来反馈一些简短信息。提示框显示后,通常自己关闭,对用户的打扰降到最低。下面简单对比一下常用两个显示对话框方式:
wx.showToast() | wx.showLoading() | |
---|---|---|
参数 | title icon image duration mask | title mask |
关闭方法 | 设置duration,定时关闭; 使用wx.hideToast()关闭 | 只能用wx.hideLoading()关闭 |
icon | success loading none | 固定显示加载icon |
showToast 举例:
wx.showToast({
title: '成功',
icon: 'success',
duration: 2000
})
showLoading 举例,在发起网络请求前显示“加载中...”,在结束时关闭信息:
wx.showLoading({
title: '加载中...',
})
wx.request({
url: ...,
...,
success: (res) => {
},
fail: () => {},
complete: () => {
wx.hideLoading()
}
})
这里是微信官方文档:https://developers.weixin.qq.com/miniprogram/dev/api/wx.showToast.html