uni 小程序自定义导航栏

复制代码
<template>
	<view class="custom-navbar" :style="{ paddingTop: statusBarHeight + 'px', height: navBarHeight + 'px' }">
		<view class="left" @click="goBack">
			<image src="../../static/logo.png" mode=""></image>
		</view>
		<view class="title">首页</view>
		<view class="right">
			<!-- 可以添加其他按钮或图标 -->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				statusBarHeight: 0,
				navBarHeight: 0
			}
		},
		created() {
			const systemInfo = uni.getSystemInfoSync();
			this.statusBarHeight = systemInfo.statusBarHeight; // 获取状态栏高度
			if (systemInfo.platform === 'android') {
				this.navBarHeight = this.statusBarHeight + 48; // Android 导航栏高度
			} else {
				this.navBarHeight = this.statusBarHeight + 44; // iOS 导航栏高度
			}
		},
		methods: {
			goBack() {
				uni.navigateBack();
			}
		}
	}
</script>

<style lang="scss" scoped>
	.custom-navbar {
		display: flex;
		justify-content: space-between;
		align-items: center;
		background-color: #FFE5E6;
		box-shadow: 0 1px 0 0 rgba(0, 0, 0, 0.1);
		padding: 0 10px;
		box-sizing: border-box;
	}

	.left,
	.right {
		width: 50rpx;
		height: 50rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		image{
			width: 100%;
			height: 100%;
		}
	}

	.title {
		flex: 1;
		text-align: center;
		font-size: 18px;
		font-weight: bold;
	}

	.iconfont {
		font-size: 20px;
	}
</style>
相关推荐
Json____8 分钟前
使用uni-app开发抖音小程序遇到previewImage方法图片加载不出来解决方案
小程序·uni-app
毕设源码-钟学长44 分钟前
【开题答辩全过程】以 基于微信小程序教学评价平台的设计与实现为例,包含答辩的问题和答案
微信小程序·小程序
说私域1 小时前
基于AI智能名片链动2+1模式S2B2C商城小程序的流量运营策略研究
人工智能·微信·小程序·产品运营·流量运营
阿巴资源站2 小时前
小程序原生授权手机号
小程序·apache
UI设计兰亭妙微2 小时前
兰亭妙微:以交互设计与UI设计赋能文旅小程序,重塑用户体验界面设计优化新标杆
小程序·ui设计外包
咖啡の猫15 小时前
微信小程序WXSS 模板样式
微信小程序·小程序
AALoveTouch1 天前
分享演唱会攻略-抢票利器
小程序·自动化
万岳科技系统开发1 天前
开源上门预约系统源码,如何实现智能排班与时间冲突校验?
小程序·开源
说私域1 天前
基于定制开发AI智能名片商城小程序的运营创新与资金效率提升研究
大数据·人工智能·小程序
qq_12498707531 天前
基于微信小程序的宠物寄领养系统(源码+论文+部署+安装)
java·spring boot·后端·微信小程序·小程序·宠物·计算机毕业设计