uniapp小程序开发遇到的问题

引用图片路径

自定义导航栏刘海屏高度适配

在app.vue里使用uni.getSystemInfo() 获取系统信息

根据右上角退出的操作按钮位置,定义导航栏高度和状态栏高度

onLaunch: function() {
            uni.getSystemInfo({
                success: function(e) {
                    // #ifndef MP
                    Vue.prototype.StatusBar = e.statusBarHeight;
                    if (e.platform == 'android') {
                        Vue.prototype.CustomBar = e.statusBarHeight + 50;
                    } else {
                        Vue.prototype.CustomBar = e.statusBarHeight + 45;
                    };
                    // #endif
                    // #ifdef MP-WEIXIN
                    Vue.prototype.StatusBar = e.statusBarHeight;
                    let custom = wx.getMenuButtonBoundingClientRect();
                    Vue.prototype.Custom = custom;
                    Vue.prototype.CustomBar = custom.bottom + custom.top - e.statusBarHeight;
                    // #endif
                    // #ifdef MP-ALIPAY
                    Vue.prototype.StatusBar = e.statusBarHeight;
                    Vue.prototype.CustomBar = e.statusBarHeight + e.titleBarHeight;
                    // #endif
                }
            })
		}

 参考colorui的cu-custom自定义导航栏组件

<template>
	<view class="my-nav-bar" :style="{height: navHeight+ 'px',paddingTop: padTop+ 'px',lineHeight: lineHeight+ 'px' }">
		<view class="nav-bar fixed" :style="{height: navHeight+ 'px',lineHeight: lineHeight+ 'px' }">
			<view class="action" @tap="BackPage" v-if="isBack">
				<text class="cuIcon-back"></text>
				<slot name="backText"></slot>
			</view>
			<view class="content">
				<slot name="content"></slot>
			</view>
		</view>
	</view>
</template>

<script>
	import Vue from 'vue'
	export default {
		name: 'my-nav-bar',
		data() {
			return {
				navHeight: '', // 导航高度
				padTop: '',  // 状态栏高度
				lineHeight: ''  // 文字垂直居中
			}
		},
		onReady() {
			this.navHeight = Vue.prototype.CustomBar
			this.padTop = Vue.prototype.StatusBar
			this.lineHeight = this.navHeight -  this.padTop
		},
		methods: {
			BackPage() {
				uni.navigateBack({
					delta: 1
				});
			}
		}
	}
</script>

<style>
	.my-nav-bar .nav-bar{
		width: 100%;
		text-align: center;
	}
</style>

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值