微信小程序wx.showToast一闪而过

伪代码

wx.showLoading()
http.reqeust({
  url: '/xxxx',
  method: 'get'
}).then(res => {
  console.log(res)
}).catch(() => {
  wx.showToast({title: '系统异常'})
}).finally((0 => {
  wx.hideLoading() 
})

网接口异常时,catch里的showToast真机一闪而过。

原因

最新版微信api wx. hideLoading()默认可以toast和loading混用,原本只是想在finally里吧loading取消掉,结果顺便把catch里的错误提示也给关闭了。
https://developers.weixin.qq.com/miniprogram/dev/api/ui/interaction/wx.hideLoading.html

解决

wx.hideLoading()改为wx.hideLoading({noConflict: true})

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容