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>
相关推荐
D_jing2019 小时前
Vue 3 + Element Plus 重置el-drawer样式失效
前端·javascript·vue.js
__log19 小时前
Vue 3 与 React 18+ 核心技术深度对比:从源码到实战
前端·vue.js·react.js
很晚很晚了1 天前
纯前端转全栈 Day 1:我从第一个 NestJS 接口开始
前端
Lee川1 天前
从零解剖一个 AI Agent Tool是如何实现的
前端·人工智能·后端
wangruofeng1 天前
Playwright 深度调研:为什么它成了浏览器自动化的新底座
前端·测试
李白的天不白1 天前
SSR服务端渲染
前端
XinZong1 天前
OpenClaw 实现「龙虾」vs 龙虾 vs 用户 ws对话实现方案 + 实际落地项目
javascript
卷帘依旧1 天前
WebSocket 比 SSE 复杂在哪里
javascript
卷帘依旧1 天前
SSE(Server-Sent Events)完全指南
前端
码云之上1 天前
万星入坞:我们如何用三层插件体系干掉巨石应用
前端·架构·前端框架