index.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. <template>
  2. <view class="container">
  3. <view class="navBarBox">
  4. <!-- 状态栏占位 -->
  5. <view class="statusBar" :style="{ paddingTop: statusBarHeight + 'px' }"></view>
  6. <!-- 真正的导航栏内容 -->
  7. <view class="navBar">
  8. 小说书城
  9. </view>
  10. </view>
  11. </view>
  12. <!-- 引入自定义 TabBar -->
  13. <custom-tabbar :currentIndex='1' />
  14. </template>
  15. <script setup>
  16. import { ref, onBeforeMount } from "vue";
  17. import CustomTabbar from "@/components/custom-tabbar.vue";
  18. // 状态栏高度
  19. let statusBarHeight = ref(0);
  20. // 导航栏高度
  21. let navBarHeight = ref(0);
  22. onBeforeMount(() => {
  23. statusBarHeight.value = uni.getSystemInfoSync()['statusBarHeight'];
  24. const custom = uni.getMenuButtonBoundingClientRect();
  25. // 导航栏的高度 = 胶囊的高度 + (胶囊距离顶部的距离 - 状态栏的高度)* 2
  26. // 即胶囊的上下边距
  27. navBarHeight.value = custom.height + (custom.top - statusBarHeight.value) * 2;
  28. });
  29. </script>
  30. <style lang="scss" scoped>
  31. .container {
  32. .navBarBox {
  33. .navBar {
  34. width: 100%;
  35. height: 80rpx !important;
  36. line-height: 80rpx;
  37. padding-left: 30rpx;
  38. font-size: 32rpx;
  39. color: #333;
  40. }
  41. }
  42. }
  43. </style>