标签:top ali data org return 简单 视图 tap 退出
uni-app写app的内容会与沉浸栏重合在一起,写好好多,都是有点问题的,这次终于找到解决的方法了,与大家分享一下
"app-plus" : {
"statusbar": {
"immersed": false
},
}
App因为默认为沉浸式,去除导航栏后,页面顶部会直通到状态栏的区域,可能出现如下需求:
<template>
<view>
<!-- #ifdef APP-PLUS -->
<view class="status_bar">
<view class="top_view"></view>
</view>
<!-- #endif -->
<view>
</view>
</view>
</template>
<script>
export default {
data() {
return {
}
},
methods: {
}
}
</script>
<style>
.status_bar {
height: var(--status-bar-height);
width: 100%;
background-color: #F8F8F8;
}
.top_view {
height: var(--status-bar-height);
width: 100%;
position: fixed;
background-color: #F8F8F8;
top: 0;
z-index: 999;
}
</style>
设置css变量后解决页面顶部会直通到状态栏的区域的问题:设置了css变量后,手机顶部状态栏区域还是会被页面内容覆盖,可使用plus.navigator.getStatusbarHeight();动态计算系统状态栏的高度barHeight,然后设置页面主view的样式:style="{‘margin-top‘:barHeight+‘px‘}",来解决。
<template> <view class="uni-flex uni-column" style="height: 100%;"> <!-- #ifdef APP-PLUS --> <view class="status_bar"> <view class="top_view"></view> </view> <!-- #endif --> <view class="uni-flex uni-row jk-bg-blue uni-center" style="height: 12%;" :style="{‘margin-top‘:barHeight+‘px‘}"> <view class="flex-sub jk-header uni-flex uni-column justify-start" @tap="test1"> <text class="text-white cuIcon-scan"></text> <text>扫码</text> </view> <view class="flex-treble jk-header uni-flex uni-column justify-center" @tap="test2"> <text class="text-white cuIcon-rank"></text> <text>统计</text> </view> <view class="flex-sub jk-header uni-flex uni-column justify-end" @click="test3"> <text class="text-white cuIcon-exit"></text> <text>退出</text> </view> </view> <view class="uni-flex align-center uni-row margin-xs" style="height: 78%;"> </view> <view class="uni-flex uni-row uni-center" style="height: 10%;color: #000000;background-color: F8F8F8;border-top: 3px solid #eee;"> </view> </view> </template> <script> var _self; export default { components: { uniPopup, }, data() { return { barHeight:25, } }, methods: { //获取系统状态栏高度 getSystemStatusBarHeight:function(){ // #ifdef APP-PLUS var height = plus.navigator.getStatusbarHeight(); _self.barHeight = height; // #endif // #ifdef H5 _self.barHeight = 0; // #endif }, }, onLoad:function(){ _self = this; _self.getSystemStatusBarHeight(); } } </script> <style> </style>
https://www.jianshu.com/p/7344c4066e82
标签:top ali data org return 简单 视图 tap 退出
原文地址:https://www.cnblogs.com/liujun1128/p/11540049.html