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>
相关推荐
不吃辣4904 小时前
vibe coding | 如何做一个AI制图小程序?
人工智能·小程序·ai编程
laboratory agent开发4 小时前
2026小程序服务商推荐:全域私域数字化工具选型深度解析
小程序
小码哥06810 小时前
智慧物业管理系统开发详解:核心功能与源码开发优势
小程序·物业管理·物业系统
汤姆yu10 小时前
基于微信小程序的方言转文字小程序的设计与实现
java·小程序·毕业设计·方言翻译
不吃辣49011 小时前
vibe coding | 如何做一个 AI 闹钟小程序?
人工智能·小程序·ai编程
万岳科技程序员小金11 小时前
在线教育系统源码开发全解析:教育培训APP、小程序及平台搭建完整方案
小程序·在线教育系统源码·教育app开发·教育小程序开发
2501_915921431 天前
appuploader-cli 命令行上传 IPA 到 App Store Connect upload CI 集成
android·ci/cd·小程序·https·uni-app·iphone·webview
梦想的旅途21 天前
企业微信销售自动化:线索分配与超时预警
小程序·自动化·企业微信
单词记忆方法研究2 天前
探索上海背单词小程序品牌:高效学习工具的优化之路
大数据·学习·小程序
码上成长2 天前
小程序请求层怎么封装?
前端·小程序