uniapp之微信小程序标题对其右上角按钮胶囊

直接上图

html 复制代码
<template>
  <!-- 在模板中使用计算后的值 -->
   <view class="indexPage" :style="{paddingTop: titleTop + 'px'}">
	    <view style="display: flex;align-items: center;justify-content: center;" :style="{height: sBarHeight +'px'}">我是标题栏标题</view>
	</view>
</template>

<script setup>
	import {
		ref,
		reactive,
		computed,
		onMounted
	} from 'vue'

	import {onLoad } from '@dcloudio/uni-app'
	// const sBarHeight = ref(uni.getSystemInfoSync().statusBarHeight)
	// const titleTop = ref(0)
    // 响应式变量的声明和数据
    const titleTop = ref(0);
    const sBarHeight = ref(0);
    
    onLoad(async (options) => {
      // 获取胶囊按钮位置信息
      const menuButtonInfo = await uni.getMenuButtonBoundingClientRect();
	  console.log(menuButtonInfo);
      const { top, height } = menuButtonInfo;
    //   // 获取系统状态栏高度
      sBarHeight.value = uni.getSystemInfoSync().statusBarHeight;

    //   // 计算标题需要偏移的位置
      titleTop.value = top + (height - sBarHeight.value) / 2;//顶部标题对齐
     
      console.log("✈️titleTop", titleTop.value);
      console.log("✈️sBarHeight ", sBarHeight .value);
    });
</script>
<style  scoped>
</style>

page.json记得把"navigationStyle": "custom"

相关推荐
专科3年的修炼1 天前
uni-app移动应用开发第四章
开发语言·javascript·uni-app
cosinmz1 天前
图片太多太乱怎么整理?分享一个我最近常用的图片转 PDF方法
经验分享·小程序·pdf
q5507071771 天前
uniapp/uniappx实现原生图片编辑涂鸦、贴图、滤镜、旋转、裁剪等
uni-app
科技互联.1 天前
2026年小程序定制市场:个性化需求激增,技术深度成竞争关键
人工智能·小程序
小羊Yveesss2 天前
2026年小程序商城的现状和发展趋势
小程序
Greg_Zhong2 天前
微信小程序如何关闭:当前渲染模式为webview?
微信小程序·微信小程序渲染引擎·渲染引擎需搭配更高基础库
橘子海全栈攻城狮2 天前
【最新源码】养老院系统管理A013
java·spring boot·后端·web安全·微信小程序
智慧景区与市集主理人2 天前
五一市集分账混乱?巨有科技智慧市集小程序实现统一收款、自动分账
大数据·科技·小程序
程序鉴定师2 天前
深圳小程序制作哪家好?2026深度市场分析与选择指南?
大数据·小程序
河北清兮网络科技2 天前
广告联盟全解析:从开发接入到运营优化,多视角拆解流量变现逻辑
小程序·app