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>
相关推荐
The_era_achievs_hero2 小时前
微信小程序41~50
微信小程序·小程序
走,带你去玩10 小时前
uniapp 微信小程序水印
微信小程序·小程序·uni-app
CC同学呀19 小时前
从0到100:单位订餐统计小程序开发日记2025
小程序
666HZ6661 天前
微信小程序中scss、ts、wxml
微信小程序·小程序·scss
二十十十十十1 天前
微信点餐小程序—美食物
微信·小程序
向明天乄1 天前
在小程序中实现实时聊天:WebSocket最佳实践
websocket·网络协议·小程序
h185385922441 天前
租车小程序电动车租赁小程序php方案
小程序
海的诗篇_1 天前
前端开发面试题总结-原生小程序部分
前端·javascript·面试·小程序·vue·html
说私域1 天前
基于开源AI智能客服、AI智能名片与S2B2C商城小程序的微商服务质量提升路径研究
人工智能·小程序·开源
拼图2091 天前
微信小程序——skyline版本问题
微信小程序·小程序