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>
相关推荐
询问QQ:4877392782 小时前
CDB文件第0x2C位置存放温度阈值
小程序
vx_vxbs663 小时前
【SSM高校普法系统】(免费领源码+演示录像)|可做计算机毕设Java、Python、PHP、小程序APP、C#、爬虫大数据、单片机、文案
android·java·python·mysql·小程序·php·idea
duansamve6 小时前
支付宝小程序开发工具中如何模拟给页面传参?
小程序·支付宝小程序
低代码布道师7 小时前
医疗预约小程序原型设计
低代码·小程序
星光一影7 小时前
同城派送系统源码,支持小程序,h5,app
mysql·小程序·php·uniapp
说私域7 小时前
基于链动2+1模式AI智能名片S2B2C商城小程序的微商运营内容研究
大数据·人工智能·小程序
云起SAAS10 小时前
计算器抖音快手微信小程序看广告流量主开源
微信小程序·小程序·ai编程·计算器·看广告变现轻
蒲公英源码10 小时前
AI智能办公系统:一体化OA解决方案,支持PC/公众号/H5/App/小程序
人工智能·小程序
弘毅 失败的 mian10 小时前
Linux 编程第一个小程序:进度条
linux·经验分享·笔记·小程序·apache