微信小程序的提示框 showToast 和 showLoading

用户操作得到即时反馈,这是很好的用户体验,所以我们经常会使用提示框来反馈一些简短信息。提示框显示后,通常自己关闭,对用户的打扰降到最低。下面简单对比一下常用两个显示对话框方式:

 

showToast 和 showLoading
 

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

  • 7
    点赞
  • 25
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值