header-view.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <template>
  2. <view class="header-view" :style="size">
  3. <slot></slot>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. name: 'HeaderView',
  9. data() {
  10. return {
  11. size: "",
  12. };
  13. },
  14. created() {
  15. // #ifdef MP
  16. let {height, top, left} = uni.getMenuButtonBoundingClientRect();
  17. this.size = `padding-top: ${top}px; min-height: ${height}px; height: max-content`;
  18. // #endif
  19. // #ifdef APP || H5
  20. let top = 0, height = 32;
  21. const {statusBarHeight} = uni.getSystemInfoSync();
  22. top += statusBarHeight;
  23. this.size = `padding-top: ${top + 10}px; min-height: ${height}px; height: max-content`;
  24. // #endif
  25. this.headerContentHeight = height;
  26. // console.log("top bar created");
  27. // let size = uni.getMenuButtonBoundingClientRect();
  28. // console.log(size);
  29. // this.size = `padding-top: ${size.top}px; min-height: ${size.height}px; height: max-content`;
  30. },
  31. methods: {
  32. getSize() {
  33. const {height, top, left} = uni.getMenuButtonBoundingClientRect();
  34. return {
  35. height,
  36. top,
  37. contentWidth: left- 7,
  38. }
  39. }
  40. }
  41. }
  42. </script>
  43. <style lang="scss" scoped>
  44. .header-view{
  45. width: 100%;
  46. padding-bottom: 10px;
  47. position: relative;
  48. }
  49. </style>