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>
相关推荐
雯0609~8 小时前
微信小程序:数据拼接方法
微信小程序·小程序
QC班长9 小时前
微信小程序引入TDesign组件后报错一直提示路径不对(Component is not found in path)的解决方法
微信小程序·小程序·tdesign·引入tdesign组件后报错
前端娱乐圈12 小时前
小程序语音识别功能 wx.createInnerAudioContext
人工智能·小程序·语音识别
Kx…………13 小时前
Uni-app入门到精通:subPackages节点为小程序的分包加载配置
前端·学习·小程序·uni-app
我血条子呢20 小时前
[微信小程序]对接sse接口
微信小程序·小程序
冰凉小脚1 天前
uniapp 自定义展开/收起组件(适配H5、微信小程序等)
微信小程序·小程序·uni-app
jieyucx1 天前
在 UniApp 编译小程序时出现 `:class` 不支持 `getStatusClass(device.deviceStatus)` 语法的报错
小程序·uni-app
jieyucx1 天前
uniapp编译小程序报错,v-for中,非 h5 平台 :key 不支持表达式 chart+‘_‘
小程序·uni-app
ALLSectorSorft1 天前
上门家政小程序,认证与安全。
安全·小程序
西木九1 天前
零基础使用AI从0到1开发一个微信小程序
人工智能·微信小程序·小程序