当前位置:   article > 正文

uniapp vue3 微信小程序 获取状态栏高度和右上角设置(胶囊按钮)高度_vue获取手机状态栏高度

vue获取手机状态栏高度

关闭原生的顶部栏

  1. // pages.json
  2. "pages": [{
  3. "path": "pages/home/index",
  4. "style": {
  5. "navigationStyle": "custom",
  6. "app-plus": {
  7. "titleView": false
  8. }
  9. }
  10. },
  11. }]

页面加载时获取胶囊高度和状态栏高度

  1. <template>
  2. <view class="bg">
  3. <view :style="{ paddingTop: topPadding }"></view>
  4. </view>
  5. </template>
  1. <script setup>
  2. import {
  3. ref,
  4. reactive,
  5. toRefs,
  6. onBeforeMount,
  7. onMounted,
  8. onUpdated,
  9. onBeforeUpdate,
  10. onBeforeUnmount,
  11. onUnmounted,
  12. computed,
  13. watch,
  14. }
  15. from 'vue'import {
  16. onLoad,
  17. onShow,
  18. onPullDownRefresh,
  19. onReachBottom,
  20. }
  21. from '@dcloudio/uni-app'
  22. let topPadding = ref('0px')
  23. const getHeight = () = >{
  24. let statusBarHeight = uni.getSystemInfoSync().statusBarHeight,
  25. customHeight = wx.getMenuButtonBoundingClientRect(),
  26. navigationBarHeight = customHeight.height + (customHeight.top - statusBarHeight) * 2
  27. topPadding.value = `$ {navigationBarHeight + statusBarHeight}px`
  28. console.log(statusBarHeight, customHeight, topPadding)
  29. }
  30. onLoad(() = >{
  31. getHeight()
  32. })
  33. </script>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/91764
推荐阅读
相关标签
  

闽ICP备14008679号