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>
相关推荐
爱折腾的编程老炮21 小时前
潮玩品牌自建抽盒机小程序——商城 + 抽盒 + 一番赏 + 会员 + 社区,一套代码怎么搭
spring boot·小程序·vue·mybatis·uniapp
新知图书1 天前
第13章 从一句话需求到上线“续费管家”小程序
人工智能·小程序·智能体
数商云企1 天前
2026年陕西软件开发首选数商云企AI微入口小程序定制方案
人工智能·小程序
bug总结2 天前
uniapp 微信小程序分包规范
微信小程序·小程序·uni-app
Quor2 天前
小程序工作室:AI 生成即运行的可视化工作台
人工智能·小程序
盟道科技2 天前
小程序电商订单超时自动取消的三种实现方案:定时扫描、Redis 过期监听、延迟消息对比与生产落地
数据库·redis·小程序
lhldsg2 天前
智慧场馆解决方案小程序系统:从架构设计到落地实践
java·小程序·需求分析
凉红茶2 天前
用Cursor开发微信小程序的第一天
微信小程序·小程序·ai编程
CRMEB系统商城2 天前
汽车养护连锁的数字化底座CRMEB 多门店系统实战方案
java·开发语言·小程序·开源·汽车
小马过河R2 天前
微信小程序自定义登录态维护:从入门到生产级落地
后端·微信小程序·小程序·架构·登录态