uniapp onshow/onLoad 中的 showToast 不显示的问题

需求: 点击底部tab页  跳转到页面中时 弹窗提示 然后页面返回某一页

很简单的需求  

uni.showToast({
  icon: 'error',
  title: '页面开发中...',
  duration: 1000,
  mask: true
})
setTimeout(()=>{
  uni.switchTab({
    url:'/pages/tabBar/home/home'
  })
},1000)

 

这样在开发工具中测试没有问题   但是在测试版中出现问题   弹窗提示在跳转前出现  并且跳转页面后不显示了

虽然目前还没发现问题原因 但是推测肯定是时机的问题  使用一层延迟 问题就解决了

setTimeout(()=>{
  uni.showToast({
    icon: 'error',
    title: '页面开发中...',
    duration: 1000,
    mask: true
  })
  setTimeout(()=>{
    uni.switchTab({
      url:'/pages/tabBar/home/home'
    })
  },1000)
},100)

 

唯一遗憾就是会有100毫秒延迟

posted on 2022-03-16 10:59  贲风  阅读(1165)  评论(0)    收藏  举报