navBar2.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <template>
  2. <view class="" :style="`height:${heights}px;`" style="width: 750rpx;">
  3. <view class="tab" >
  4. <view class="neirong" style="width: 100%;"
  5. :style="`height:${heights-top}px;font-size:${(heights-top)*0.6}px;margin-top:${top}px;`">
  6. <image @click="fanHuiFn()" class="img" src="@/static/icon_fanhui@2x.png" mode=""></image>
  7. {{text}}
  8. </view>
  9. </view>
  10. </view>
  11. </template>
  12. <script lang="ts" setup>
  13. import { ref } from 'vue'
  14. let text = ref()// tab的文字内容
  15. let heights = ref()//顶部高度(以胶囊底部为准)
  16. let top = ref()//胶囊顶部距离顶部高度
  17. const jiaoNang = ref()//获取胶囊位置信息
  18. // 获取页面传来的tab内容
  19. const props = defineProps({
  20. text: {
  21. type: String,
  22. },
  23. })
  24. // 返回前一个页面
  25. const fanHuiFn=()=>{
  26. uni.navigateBack({
  27. delta:1
  28. })
  29. }
  30. text.value = props.text
  31. // 获取顶部胶囊位置
  32. jiaoNang.value = uni.getMenuButtonBoundingClientRect()
  33. // 保存胶囊底部到屏幕顶部高度
  34. heights.value = jiaoNang.value.height + jiaoNang.value.top
  35. // 保存胶囊顶部到屏幕顶部高度
  36. top.value = jiaoNang.value.top
  37. </script>
  38. <style lang="scss">
  39. .tab {
  40. position: fixed;
  41. top: 0;
  42. left: 0;
  43. text-align: center;
  44. overflow: hidden;
  45. background-color: #fff;
  46. color: #333;
  47. z-index: 10000;
  48. width: 750rpx;
  49. // background-color: #fff;
  50. color: #333;
  51. .neirong{
  52. position: relative;
  53. .img{
  54. position: absolute;
  55. top: 10rpx;
  56. left: 20rpx;
  57. width: 26rpx;
  58. height: 32rpx;
  59. }
  60. }
  61. }
  62. </style>