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"

相关推荐
社会渣渣17 小时前
开发者工具正常、真机白屏:一次渲染差异排查
微信小程序
daguanren19 小时前
一个页面外壳,多页复用:weapp-vite / Wevu 布局的编译与动态切换
微信小程序
源码手记20 小时前
基于微信小程序的上门代厨厨师预约系统-毕设源码
微信小程序·小程序·课程设计
微订校园外卖系统20 小时前
自建自营小程序落地前,先把订单状态机与试单链路跑通
小程序·外卖系统·本地生活·微订
千寻技术帮20 小时前
基于微信小程序的点餐管理系统_50044(源码+脚本+文档)
mysql·微信小程序·小程序·毕业设计·springboot·点餐管理系统
AI源码21 小时前
中医药文化介绍小程序
小程序·notepad++
千寻技术帮2 天前
基于微信小程序的零食销售系统(源码+文档+脚本)50047
数据库·mysql·微信小程序·小程序·毕业设计·springboot·课程设计
源码手记2 天前
基于微信小程序的驾考刷题学习系统-毕设源码
学习·微信小程序·课程设计
lyz2468592 天前
uniapp-x在小程序使用uchart图表加载问题
小程序·uni-app
AI源码2 天前
心理健康教育小程序
小程序