cl-safe-area.uvue 724 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <template>
  2. <view
  3. class="cl-safe-area"
  4. :class="[pt.className]"
  5. :style="{
  6. height
  7. }"
  8. >
  9. <slot></slot>
  10. </view>
  11. </template>
  12. <script setup lang="ts">
  13. import { getSafeAreaHeight, parsePt } from "@/.cool";
  14. import { computed, type PropType } from "vue";
  15. defineOptions({
  16. name: "cl-safe-area"
  17. });
  18. const props = defineProps({
  19. pt: {
  20. type: Object,
  21. default: () => ({})
  22. },
  23. type: {
  24. type: String as PropType<"top" | "bottom">,
  25. default: "top"
  26. },
  27. transparent: {
  28. type: Boolean,
  29. default: false
  30. }
  31. });
  32. type PassThrough = {
  33. className?: string;
  34. };
  35. const pt = computed(() => parsePt<PassThrough>(props.pt));
  36. // 高度
  37. const height = computed(() => {
  38. return getSafeAreaHeight(props.type) + "px";
  39. });
  40. </script>