随笔 - 21  文章 - 0  评论 - 0  阅读 - 3274

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

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

onshow/onLoad 

很简单的需求  

uni.showToast({
  icon: 'error',
  title: '页面开发中...',
  duration: 1000,
  mask: true
})


setTimeout(()=>{
  uni.switchTab({
    url:'/pages/tabBar/home/home'
  })
},1000)

类似的其他框架方式:

    onShow(){
            //必须使用延时功能,否则报错
            setTimeout(()=>{
        this.$refs.uToast.show({title: "查询中...!",type:'info',position:'bottom',duration:3000});},3000);

}

onReady() 、、//同样适用

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

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

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

 

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

posted on   侗家小蚁哥  阅读(305)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

点击右上角即可分享
微信分享提示