uni.hideTabBar隐藏底部默认tabbar的问题
问题描述
先看官方说明:
https://uniapp.dcloud.net.cn/api/ui/tabbar.html#hidetabbar
今天有个需求需要隐藏底部tabbar,我是这样写的:
在App.vue中
<script>
	export default {
		globalData: {
			...
		},
		onLaunch: async function() {
			console.log('App Launch');
			 uni.hideTabBar();
		},
		onShow: function() {
			console.log('App Show');
			uni.hideTabBar();
		},
		onHide: function() {
			console.log('App Hide')
		}  
	}
</script>在浏览器上正常,但是到了真机上,发现是无效的,后来调用:
uni.hideTabBar({
	fail() {
		console.log(11)
	},
	success() {
		console.log(22)
	}
});在手机上打印出来的也是11,调用接口失败。
解决方法
感谢以下链接:
https://ask.dcloud.net.cn/question/90833
我的猜测是需要延时一会,我定时0.3s之后再执行,然后就正常了
其中一个网友是如上回复的。于是我尝试使用一个定时器,发现真机上也取消了!最终改为如下:
<script>
	export default {
		globalData: {
			....
		},
		onLaunch: async function() {
			console.log('App Launch');
			setTimeout(() => {
				uni.hideTabBar();
			}, 1000); 
			// uni.hideTabBar();
		},
		onShow: function() {
			console.log('App Show');
			// uni.hideTabBar();
		},
		onHide: function() {
			console.log('App Hide')
		}  
	}
</script>当然,如此操作需要在manifest.json中设置,设置手动隐藏原生的加载界面,具体实现可以参考我的另一篇文章:
"splashscreen" : {
            "alwaysShowBeforeRender" : false,
            "waiting" : false,
            "autoclose" : false,
            "delay" : 0
},然后再利用回调,关闭等待层:
plus.navigator.closeSplashscreen() 
                     
                     
                     
                     
                     
                     
                     
             
             
             目录
        目录