uniapp 设置安全区域

javascript 复制代码
<!-- 获取安全区域 -->
<script setup lang="ts">
import { computed, ref } from 'vue'

let systemType = ref('1')
// #ifdef APP-PLUS || H5  || APP-PLUS-NVUE
systemType.value = '1'
const { safeAreaInsets } = uni.getSystemInfoSync()
console.log(safeAreaInsets, 'safeAreaInsets')
const prop = defineProps({
  title: {
    type: String,
    default: '消息',
  },
})
// #endif

// #ifdef MP-WEIXIN
systemType.value = '2'
const navbarHeight = ref(0)
//计算刘海状态栏
navbarHeight.value = uni.getSystemInfoSync().statusBarHeight || 0
//计算胶囊区域的高度
let { top, height } = uni.getMenuButtonBoundingClientRect()
const titleBarHeight = computed(() => {
  return (top - navbarHeight.value) * 2 + height
})
// #endif
</script>

<template>
  <view v-if="systemType == '1'" class="navbar" :style="{ paddingTop: safeAreaInsets?.top + 'rpx' }">
    <view class="search">{{ title }}</view>
  </view>
  <view v-if="systemType == '2'">
    <view class="fill" :style="{ height: navbarHeight + 'px' }"></view>
    <view class="title" :style="{ height: titleBarHeight + 'px' }"> 消息 </view>
  </view>
</template>

<style lang="scss">
.navbar {
  background-size: cover;
  position: relative;
  display: flex;
  flex-direction: column;
  padding-top: 20px;
  // .leftBack {
  //   position: absolute;
  //  top: 200rpx;
  // }
  .search {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0rpx 10rpx 0 26rpx;
    height: 64rpx;
    line-break: 64rpx;
    //ui标记距离上面22rpx
    margin: 44rpx 20rpx 0 20rpx;
    color: #1f1f1f;
    font-weight: 600;
    font-size: 28rpx;
    border-radius: 32rpx;
  }
}
.fill {
  width: 100%;
}
.title {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
</style>

uniapp 设置安全区域以及导航栏和胶囊对齐 要注意app没有胶囊没法获取 要另外写样式(已完善)

ps:真就是每个公司总有那么几个表现狗 真他妈的恶心 得拓展一下自己的知识宽度 找下家了

相关推荐
麦麦大数据19 分钟前
J002 Vue+SpringBoot电影推荐可视化系统|双协同过滤推荐算法评论情感分析spark数据分析|配套文档1.34万字
vue.js·spring boot·数据分析·spark·可视化·推荐算法
2501_915909062 小时前
HTTPS 错误解析,常见 HTTPS 抓包失败、443 端口错误与 iOS 抓包调试全攻略
android·网络协议·ios·小程序·https·uni-app·iphone
BillKu5 小时前
Vue3 + Element-Plus 抽屉关闭按钮居中
前端·javascript·vue.js
DevilSeagull5 小时前
JavaScript WebAPI 指南
java·开发语言·javascript·html·ecmascript·html5
面向星辰5 小时前
html中css的四种定位方式
前端·css·html
Async Cipher6 小时前
CSS 权重(优先级规则)
前端·css
大怪v6 小时前
前端佬:机器学习?我也会啊!😎😎😎手“摸”手教你做个”自动驾驶“~
前端·javascript·机器学习
Liquad Li6 小时前
Angular 面试题及详细答案
前端·angular·angular.js
源码师傅6 小时前
uniapp开源多商户小程序商城平台源码 支持二次开发+永久免费升级
小程序·uni-app·多商户商城源码·uniapp开源商城源码·开源多商户小程序商城平台·商城小程序代码·多商户商城小程序源码
用户21411832636027 小时前
首发!即梦 4.0 接口开发全攻略:AI 辅助零代码实现,开源 + Docker 部署,小白也能上手
前端