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>
相关推荐
说私域17 小时前
基于开源AI大模型的AI智能名片在S2B2C商城小程序维度表重复数据整理中的应用及效果研究
人工智能·小程序
云起SAAS20 小时前
图文小程序内无实质业务服务功能体验不完整解决小程序开源
小程序
毕设源码-朱学姐21 小时前
【开题答辩全过程】以 干洗店预约服务小程序为例,包含答辩的问题和答案
小程序
百锦再21 小时前
Elements Plus 跨设备自适应显示问题综合解决方案
python·flutter·小程序·uni-app·k8s·tornado·net
毕设源码-邱学长1 天前
【开题答辩全过程】以 基于微信小程序的实验耗材申报平台的设计与实现为例,包含答辩的问题和答案
微信小程序·小程序
说私域1 天前
基于开源AI智能名片链动2+1模式商城系统的创始人个人品牌资产构建研究
人工智能·小程序·开源
sheji34161 天前
【开题答辩全过程】以 基于微信小程序的手机数码交易平台为例,包含答辩的问题和答案
微信小程序·小程序
项目題供诗1 天前
微信小程序黑马优购(项目)(十二)
微信小程序·小程序
luffy54591 天前
微信小程序组件与父页面传值示例
微信小程序·小程序
百锦再2 天前
抖音小程序开发全景透视:生态解析、技术架构与商业实践
人工智能·ai·微信小程序·小程序·架构·模型·抖音