微信小程序自定义顶部导航栏,动态适状态栏标题包括胶囊

微信小程序自定义顶部导航栏,动态适配包括胶囊

html 复制代码
<view>
	<uni-nav-bar :height="totalHeight" backgroundColor="#FFC003" leftWidth="100%">
			<block slot="left">
				<view>
					<view class="navTitle">
						哈哈哈
					</view>
				</view>
			</block>
		</uni-nav-bar>
</view>
javascript 复制代码
menu: [],
statusBarHeight: 0, //状态栏的高度 
navigatorHeight: 0, //导航栏高度
menuHeight: 0, //胶囊高度
menuTop: 0, //胶囊与顶部的距离
totalHeight: 0, //总高度 
onShow() {
	// 获取系统信息
	uni.getSystemInfo({
		success: res => {
			this.system = res;
			this.statusBarHeight = this.system.statusBarHeight; // 状态栏高度
			this.calculateNavBarHeight()
		}
	});
},
methods:{
	calculateNavBarHeight() {
		// 获取胶囊信息
		this.menu = uni.getMenuButtonBoundingClientRect();
		// 计算组件高度
		this.menuHeight = this.menu.height; // 胶囊高度
		this.menuTop = this.menu.top; // 胶囊与顶部的距离
		// 导航栏高度= (胶囊顶部距离-状态栏高度) x 2 + 胶囊的高度
		this.navigatorHeight = (this.menu.top - this.system.statusBarHeight) * 2 + this.menu.height;
		// 总高度 = 状态栏的高度 + 导航栏高度    
		this.totalHeight = this.statusBarHeight + this.navigatorHeight;
	 },
}
css 复制代码
	.navTitle {
		padding-left: 36rpx;
		font-family: PingFang SC, PingFang SC;
		font-weight: bold;
		font-size: 36rpx;
		color: #000000;
		margin-bottom: 10rpx;
	}
相关推荐
汤姆yu2 小时前
基于微信小程序的学校招生系统
微信小程序·小程序·招生小程序
说私域9 小时前
基于开源AI智能名片链动2+1模式的S2B2C商城小程序:门店私域流量与视频号直播融合的生态创新研究
人工智能·小程序·开源
说私域11 小时前
传统微商困境与开源链动2+1模式、AI智能名片及S2B2C商城小程序的转型破局
人工智能·小程序·开源
一渊之隔11 小时前
微信小程序在用户拒绝授权后无法使用wx.opensetting再次获取定位授权
微信小程序·小程序
racerun15 小时前
微信小程序如何实现再多个页面共享数据
微信小程序·小程序
XM-545816 小时前
2025微信小程序wxapkg解包全攻略
linux·运维·小程序
HERR_QQ2 天前
【unify】unify的微信小程序开发学习 (to be continued)
学习·微信小程序·小程序
racerun2 天前
小程序导航设置更多内容的实现方法
小程序
说私域2 天前
基于开源AI智能名片链动2+1模式S2B2C商城小程序的超级文化符号构建路径研究
人工智能·小程序·开源
mg6682 天前
微信小程序入门实例_____快速搭建一个快递查询小程序
微信小程序·小程序