【uniapp】自定义导航栏时,设置安全距离,适配不同机型

1、在pages.json中,给对应的页面设置自定义导航栏样式

bash 复制代码
    {
      "path": "pages/index/index",
      "style": {
        "navigationStyle": "custom",
        "navigationBarTextStyle": "white",
         "navigationBarTitleText": "首页",
      }
    },

2、定义自定义组件customNavbar,在组件中获取屏幕边界到安全区域的距离

bash 复制代码
<template>
  <view class="navbar" :style="{paddingTop:safeAreaInsets?.top+'px'}">
	<view class="logo">
		<image src="../../static/c1.png" mode=""></image>
		<text>头部导航</text>
	</view>
  >
  <view>
  	<text class="icon-search">搜索</text>
	<text class="icon-scan"></text>
  </view>
  </view>
</template>
<script lang="ts" setup>
const {safeAreaInsets} =uni.getSystemInfoAsync()

console.log(safeAreaInsets)

</script>
相关推荐
無限進步D30 分钟前
Java 运行原理
java·开发语言·入门
是苏浙33 分钟前
JDK17新增特性
java·开发语言
阿里加多4 小时前
第 4 章:Go 线程模型——GMP 深度解析
java·开发语言·后端·golang
likerhood4 小时前
java中`==`和`.equals()`区别
java·开发语言·python
小李子呢02115 小时前
前端八股性能优化(2)---回流(重排)和重绘
前端·javascript
zs宝来了5 小时前
AQS详解
java·开发语言·jvm
telllong6 小时前
Python异步编程从入门到不懵:asyncio实战踩坑7连发
开发语言·python
吴声子夜歌7 小时前
Vue3——Vue实例与数据绑定
前端·javascript·vue.js
wjs20247 小时前
JavaScript 条件语句
开发语言
阿里加多7 小时前
第 1 章:Go 并发编程概述
java·开发语言·数据库·spring·golang