【uni-app】对齐胶囊容器组件

代码碎片

html 复制代码
<template>
  <div>
    <view :style="{ height: `${statusBarHeight}px` }"></view>
    <view
      class=""
      :style="{
        height: `${menuButtonHeight + menuButtonPadding * 2}px`,
        width: `${menuButtonInfo.left}px`,
      }"
    >
      <slot name="left"></slot>
      <slot name="mid"></slot>
    </view>
  </div>
</template>

<script lang="ts" setup>
const menuButtonInfo = uni.getMenuButtonBoundingClientRect() // 胶囊按钮信息
const statusBarHeight = uni.getSystemInfoSync().statusBarHeight // 系统信息里的状态栏高度

console.log('menuButtonInfo', menuButtonInfo)
console.log('statusBarHeight', statusBarHeight)
const menuButtonPadding = menuButtonInfo.top - statusBarHeight
const menuButtonHeight = menuButtonInfo.height
</script>

<style lang="scss" scoped>
//
</style>
相关推荐
ZC跨境爬虫5 小时前
跟着 MDN 学 HTML day_9:(信件语义标记)
前端·css·笔记·ui·html
前端老石人5 小时前
HTML 字符引用完全指南
开发语言·前端·html
幼儿园技术家5 小时前
前端如何设计权限系统(RBAC / ABAC)?
前端
前端摸鱼匠7 小时前
Vue 3 的v-bind合并行为:讲解v-bind与普通属性合并的规则
前端·javascript·vue.js·前端框架·ecmascript
REDcker7 小时前
浏览器端Web程序性能分析与优化实战 DevTools指标与工程清单
开发语言·前端·javascript·vue·ecmascript·php·js
donecoding9 小时前
一个 sudo 引发的血案:npm 全局包权限错乱彻底修复
前端·node.js·前端工程化
风骏时光牛马9 小时前
Raku正则匹配与数据批量处理实操案例
前端
nbwenren9 小时前
2026实测:Gemini 3 镜像站视觉能力实践——拍照原型图,一键生成 HTML+CSS 代码
前端·css·html
Lee川9 小时前
Prisma 实战指南:像搭积木一样设计古诗词数据库
前端·数据库·后端