解决uniapp中使用uni.showToast在真机微信小程序中一闪而逝的bug

725 阅读1分钟

1.出现原因 场景一:
wx.hideLoading()会关闭同级中的wx.showLoading 或 wx.showToast 所以要在showToast之前调用wx.hideLoading

场景二:
showToast不会出现在打开的新的页面中
解决方案: 延迟调用showToast,保证showToast在hideLoading之后执行

setTimeout(() => {
   uni.showToast({
      title: i18n.t('index.serverWrong'),
      duration: 2500,
      icon: 'none'
   })
}, 0)