uniapp自定义导航头,页面内容自动盛满禁止滚动效果

1.pages.jso设置自定义头部 "navigationStyle": "custom"

复制代码
{
			"path" : "pages/a/a",
			"style" : 
			{
				"navigationBarTitleText" : "自定义头",
				"navigationStyle": "custom"
			}
		},

2.效果 源码

复制代码
<template>
  <view class="container">
    <view class="custom-navbar" :style="{ height: navBarHeight + 'px' }">
      <view class="title" :style="{ top: titleTop + 'px', height: titleHeight + 'px' }">
        123
      </view>
    </view>

    <view class="content">
      <text>asasa</text>
    </view>
  </view>
</template>
<script>
export default {
  data() {
    return {
      navBarHeight: 0,  
      titleTop: 0,  
      titleHeight: 0 
    };
  },
  onLoad() {
    this.calculateNavBarHeight();
  },
  methods: {
    calculateNavBarHeight() {
      const systemInfo = uni.getSystemInfoSync();
      const menuButtonInfo = uni.getMenuButtonBoundingClientRect();
      this.navBarHeight = menuButtonInfo.bottom + (menuButtonInfo.top - systemInfo.statusBarHeight);

      this.titleTop = menuButtonInfo.top;

      this.titleHeight = menuButtonInfo.height;
    }
  }
};
</script>
<style>
  .container {
    display: flex;
    flex-direction: column;
    height: 100vh;
  }

  .custom-navbar {
    background-color: red;
    position: relative; 
  }

  .title {
    position: absolute;
    left: 50%;  
    transform: translateX(-50%); 
    color: white;
    font-size: 16px;
    font-weight: bold;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .content {
    flex: 1;  
    background-color: green;
    display: flex;
    align-items: center;
    justify-content: center;
  }
</style>
相关推荐
零度晚风2 分钟前
JS:基础语法与控制结构
javascript
锋行天下4 分钟前
关于websocket,真实场景踩坑经验
前端·后端
Asize9 分钟前
重生之我在 Vibe Coding 时代当程序员:第十二课,Prompt 不是咒语,是可以沉淀的业务接口
前端·人工智能·python
布兰妮甜34 分钟前
Vue 项目 `localhost:3000` 打不开?404 常见原因排查指南
前端·javascript·vue.js·vuecli·4040排查
森林的尽头是阳光38 分钟前
前端使用postman快速造数据
前端·javascript·vue·postman·造数·本地测试
小猿备忘录1 小时前
Spring Security OAuth2 双Token机制精讲:原理、配置与常见坑点全解析
java·前端·spring·中间件
丷丩1 小时前
MapLibre GL JS第38课:根据缩放级别改变建筑颜色
javascript·map·mapbox·maplibre gl js
许彰午1 小时前
12_ArrayList与LinkedList深度对比
java·前端·python
lichenyang4532 小时前
鸿蒙练习 12:Provider/Consumer 跨层共享 + HAR 多模块拆分
前端
朱涛的自习室2 小时前
逃离“古法测试”:AI 测试的“三大定律”
android·前端·人工智能