【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>
相关推荐
紫金修道1 小时前
【DeepAgent】概述
开发语言·数据库·python
Via_Neo1 小时前
JAVA中以2为底的对数表示方式
java·开发语言
书到用时方恨少!2 小时前
Python multiprocessing 使用指南:突破 GIL 束缚的并行计算利器
开发语言·python·并行·多进程
cch89182 小时前
PHP五大后台框架横向对比
开发语言·php
天真萌泪2 小时前
JS逆向自用
开发语言·javascript·ecmascript
野生技术架构师2 小时前
一线大厂Java面试八股文全栈通关手册(含源码级详解)
java·开发语言·面试
柳杉3 小时前
震惊!字符串还能这么玩!
前端·javascript
Q一件事3 小时前
R语言制图-相关性及关系网络图
开发语言·r语言
坊钰3 小时前
Java 死锁问题及其解决方案
java·开发语言·数据库
仍然.4 小时前
算法题目---模拟
java·javascript·算法