【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>
相关推荐
不做Java程序猿好多年17 小时前
Java中 String、StringBuffer、StringBuilder 的区别详解
开发语言·python
会周易的程序员17 小时前
js-shm: 高性能 Node.js 共享内存模块
开发语言·javascript·c++·node.js·共享内存·shm
笨蛋不要掉眼泪17 小时前
Java虚拟机:常用参数
java·开发语言·python
带娃的IT创业者17 小时前
重新定义前端构建速度:深度解析 SWC 如何用 Rust 颠覆 JavaScript 工具链
前端·javascript·rust·前端构建·swc
happy_0x3f18 小时前
前端应用的离线暂停更新策略
开发语言·前端·php
m0_5474866618 小时前
《Vue.js + uni-app全栈开发从入门到实践 》全套PPT课件2026版
vue.js·uni-app
shylyly_18 小时前
C++中的类型转换
开发语言·c++·匿名对象·隐式类型转换·拷贝优化
新中地GIS开发老师19 小时前
零基础WebGIS开发入门 | GeoJSON数据持久化
前端·javascript·gis·webgis·三维gis开发
北冥you鱼19 小时前
Go 语言新手扫盲:指针 * 和 & 使用场景详解
开发语言·后端·golang
cui_ruicheng19 小时前
Python数据分析(一):数据分析概述与环境搭建
开发语言·python·数据分析