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>
相关推荐
00后程序员张9 小时前
python 抓包在实际项目中的合理位置,结合代理抓包、设备侧抓包与数据流分析
android·ios·小程序·https·uni-app·iphone·webview
2501_9159184116 小时前
使用 HBuilder 上架 iOS 应用时常见的问题与应对方式
android·ios·小程序·https·uni-app·iphone·webview
2501_9160074718 小时前
iOS 崩溃日志的分析方法,将崩溃日志与运行过程结合分析
android·ios·小程序·https·uni-app·iphone·webview
2501_9160074719 小时前
React Native 混淆在真项目中的方式,当 JS 和原生同时暴露
javascript·react native·react.js·ios·小程序·uni-app·iphone
00后程序员张19 小时前
苹果应用商店上架App流程,签名证书、IPA 校验、上传
android·ios·小程序·https·uni-app·iphone·webview
2501_9160074719 小时前
iOS 上架需要哪些准备,围绕证书、描述文件和上传方式等关键环节展开分析
android·ios·小程序·https·uni-app·iphone·webview
qq_124987075319 小时前
基于微信小程序的私房菜定制上门服务系统(源码+论文+部署+安装)
java·spring boot·微信小程序·小程序·毕业设计·毕设
2501_9151063219 小时前
iOS 上架费用解析,哪些成本可以通过流程优化降低。
android·ios·小程序·https·uni-app·iphone·webview
风月歌21 小时前
小程序项目之超市售货管理平台小程序源代码(源码+文档)
java·微信小程序·小程序·毕业设计·源码
Lily.C21 小时前
小程序WebSocket实时通信全解析
websocket·网络协议·小程序