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:真就是每个公司总有那么几个表现狗 真他妈的恶心 得拓展一下自己的知识宽度 找下家了

相关推荐
flashlight_hi几秒前
LeetCode 分类刷题:110. 平衡二叉树
javascript·算法·leetcode
Beginner x_u2 分钟前
Vue 事件机制全面解析:原生事件、自定义事件与 DOM 冒泡完全讲透
前端·javascript·vue.js·dom
Emma_Maria2 分钟前
关于vant-ui-vue 的datepicker 时间选择错乱问题的处理
前端·vue.js·ui
Dabei7 分钟前
Android 语音助手简单实现与语音助手“执行任务”交流
android·前端
dongczlu9 分钟前
iOS 循环引用篇 菜鸟都能看懂
前端
Alsn8611 分钟前
26.IDEA 专业版中创建简单的 Web 项目并打包部署到本地Tomcat 9
前端·tomcat·intellij-idea
霍理迪12 分钟前
HTML行内块标签——img、表单、音视频标签
前端·html
小小前端_我自坚强13 分钟前
边缘函数 (Edge Functions)详解
前端
咸虾米_14 分钟前
开发uniapp前端通用价格组件提交到DCloud插件市场
uni-app·商城·开发插件·dcloud插件市场·扩展组件
幼儿园技术家21 分钟前
Hydration Mismatch 原理详解:SSR 项目中最容易踩的坑
前端