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>
相关推荐
chaffererdog4 小时前
uniapp开发微信小程序使用vk-uview-ui的uSearch搜索组件,在微信开发者工具中点击输入框会意外触发custom事件
微信小程序·小程序·uni-app
2501_9159184110 小时前
Flutter 加固方案全解析,从 Dart 层到 IPA 成品的多工具协同防护体系
flutter·macos·ios·小程序·uni-app·cocoa·iphone
我命由我1234510 小时前
微信小程序 - 内容弹出框实现(Vant Weapp 实现、原生实现)
开发语言·前端·javascript·微信小程序·小程序·前端框架·js
小码哥06811 小时前
陪诊小程序核心功能拆解:预约、导航与提醒
小程序·项目源码·预约系统·陪诊·陪诊系统开发
q_191328469512 小时前
基于Springboot+uniapp的智慧停车场收费小程序
java·vue.js·spring boot·小程序·uni-app·毕业设计·计算机毕业设计
2501_9160074712 小时前
深入理解 iOS 文件管理体系,从沙盒结构到多工具协同的工程化文件管理实践
android·ios·小程序·https·uni-app·iphone·webview
00后程序员张12 小时前
iOS 性能检测工具深度解析 多工具协同下的全维度性能检测体系建设
android·ios·小程序·https·uni-app·iphone·webview
说私域12 小时前
天猫卖家运营突围:基于开源AI智能名片链动2+1模式S2B2C商城小程序的转型路径研究
人工智能·小程序·开源
00后程序员张12 小时前
Fiddler调试工具全面解析 HTTPHTTPS抓包、代理设置与接口测试实战教程
前端·测试工具·ios·小程序·fiddler·uni-app·webview
Alex8132012 小时前
scheme跳转小程序 打不开知道指定页
小程序