【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>
相关推荐
Elias不吃糖3 小时前
Java Lambda 表达式
java·开发语言·学习
guygg883 小时前
一级倒立摆MATLAB仿真程序
开发语言·matlab
情缘晓梦.3 小时前
C语言指针进阶
java·开发语言·算法
世转神风-4 小时前
qt-字符串版本与数值版本互转
开发语言·qt
极客代码4 小时前
深入解析C语言中的函数指针:原理、规则与实践
c语言·开发语言·指针·状态机·函数·函数指针
美酒没故事°4 小时前
vue3拖拽+粘贴的综合上传器
前端·javascript·typescript
w-w0w-w4 小时前
C++模板参数与特化全解析
开发语言·c++
不绝1914 小时前
C#核心:继承
开发语言·c#
AI即插即用5 小时前
即插即用系列(代码实践)专栏介绍
开发语言·人工智能·深度学习·计算机视觉