navBar.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <view class="" :style="`paddingTop:${heights}px;`" style="width: 750rpx;">
  3. <view class="tab">
  4. <view class="">
  5. {{text}}
  6. </view>
  7. </view>
  8. </view>
  9. </template>
  10. <script setup>
  11. import { ref } from 'vue'
  12. const text = ref()// tab的文字内容
  13. const heights = ref('20')//顶部高度(以胶囊底部为准)
  14. // let top = ref()//胶囊顶部距离顶部高度
  15. // const jiaoNang = ref()//获取胶囊位置信息
  16. // 获取页面传来的tab内容
  17. const props = defineProps({
  18. text: {
  19. type: String,
  20. },
  21. })
  22. text.value = props.text
  23. // // 获取顶部胶囊位置
  24. // jiaoNang.value = uni.getMenuButtonBoundingClientRect()
  25. // // 保存胶囊底部到屏幕顶部高度
  26. // heights.value = jiaoNang.value.height + jiaoNang.value.top
  27. // // 保存胶囊顶部到屏幕顶部高度
  28. // top.value = jiaoNang.value.top
  29. const getPhoneInfo = () => {
  30. const phoneInfo = uni.getSystemInfoSync(); // 获取手机系统信息
  31. // let statusBarObj = {
  32. // statusBarHeight: 20
  33. // }
  34. // 设置状态栏高度(H5顶部无状态栏小程序有状态栏需要撑起高度)
  35. console.log(phoneInfo,'高度信息啊')
  36. heights.value = phoneInfo.statusBarHeight;
  37. }
  38. getPhoneInfo()
  39. </script>
  40. <style lang="scss">
  41. .tab {
  42. // position: fixed;
  43. // top: 0;
  44. // left: 0;
  45. text-align: center;
  46. overflow: hidden;
  47. background-color: #fff;
  48. color: #333;
  49. // z-index: 10000;
  50. width: 750rpx;
  51. height: 90rpx;
  52. line-height: 90rpx;
  53. }
  54. </style>