custom-navbar.vue 938 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <template>
  2. <view class="custom-navbar">
  3. <!-- 状态栏占位 -->
  4. <view class="status-bar" :style="{ height: statusBarHeight + 'px' }"></view>
  5. <!-- 导航栏主体 -->
  6. <view class="navbar-content" :style="{ height: navBarHeight + 'px' }">
  7. <slot></slot>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. name: 'custom-navbar',
  14. data() {
  15. return {
  16. statusBarHeight: 0,
  17. navBarHeight: 44, // 导航栏高度,单位px
  18. }
  19. },
  20. created() {
  21. // 获取状态栏高度
  22. const systemInfo = uni.getSystemInfoSync()
  23. this.statusBarHeight = systemInfo.statusBarHeight
  24. }
  25. }
  26. </script>
  27. <style>
  28. .custom-navbar {
  29. width: 100%;
  30. position: fixed;
  31. top: 0;
  32. left: 0;
  33. z-index: 999;
  34. background-color: transparent;
  35. }
  36. .status-bar {
  37. width: 100%;
  38. background-color: transparent;
  39. }
  40. .navbar-content {
  41. width: 100%;
  42. display: flex;
  43. align-items: center;
  44. background-color: transparent;
  45. }
  46. </style>