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>
相关推荐
paopaokaka_luck4 小时前
停车小程序(车牌OCR智能识别、地图API、Echarts图形化分析、智能车位预约、自动计费与订单处理)
小程序·ocr·echarts
单词记忆方法研究6 小时前
大学英语单词:我踩过的坑,和你该走的路
机器学习·小程序·学习方法
Ai-_Man9 小时前
怎么手动备份豆包智能体的聊天数据?
人工智能·ai·小程序
Ai-_Man13 小时前
豆包收藏夹能批量导出吗?从底层逻辑拆解「AI导出鸭」如何解构这一技术难题
人工智能·ai·小程序
微擎应用16 小时前
小程序抽奖工具
小程序
Ai-_Man21 小时前
希望大家能推荐一款软件,可以直接把文心生成的代码变流程图,提高办公效率
人工智能·ai·小程序·流程图
Chengbei111 天前
DSH渗透测试插件dsh-pentest全新升级!适配DeepSeek Harness,可视化探索链路,一键搭建轻量化AI渗透测试环境。
人工智能·web安全·网络安全·微信·小程序·系统安全·安全架构
2601_949950631 天前
用练题簿小程序把课件做成可以在线刷题的内容
小程序·练习·小程序推荐
一几文1 天前
2026年上半年软考高级-系统架构设计师考试真题回顾与解析-综合知识选择题6
小程序·架构·系统架构·软考高级·软考·it证书
zhangminghuan1 天前
微信小程序开发核心知识点全景解析(前端必备硬核基础)
前端·微信小程序·小程序