【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>
相关推荐
晴殇i1 天前
DOM嵌套关系全解析:前端必备的4大判断方法与性能优化实战
前端·javascript·面试
iOS阿玮1 天前
AppStore卡审44小时的产品,重新提交后已经过审了。
uni-app·app·apple
北城以北88881 天前
SSM--MyBatis框架之动态SQL
java·开发语言·数据库·sql·mybatis
QuantumLeap丶1 天前
《uni-app跨平台开发完全指南》- 04 - 页面布局与样式基础
vue.js·微信小程序·uni-app
字节拾光1 天前
console.log 打印 DOM 后内容变了?核心原因是 “引用” 而非 “快照”
javascript
木易 士心1 天前
Android 开发核心技术深度解析
android·开发语言·python
程序员烧烤1 天前
【Java基础14】函数式接口、lamba表达式、方法引用一网打尽(下)
java·开发语言
lzq6031 天前
Python虚拟环境全指南:venv与conda对比与实践
开发语言·python·conda
Asort1 天前
React函数组件深度解析:从基础到最佳实践
前端·javascript·react.js
小年糕是糕手1 天前
【数据结构】常见的排序算法 -- 插入排序
c语言·开发语言·数据结构·学习·算法·leetcode·排序算法