HomeSection.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <script setup lang="ts">
  2. import { toRefs, computed, useSlots, h } from "vue";
  3. import { useBreakpoints } from "@vueuse/core";
  4. const props = defineProps<{
  5. title?: string;
  6. }>();
  7. const { title } = toRefs(props);
  8. const breakpoints = useBreakpoints({
  9. tablet: 640,
  10. laptop: 1024,
  11. desktop: 1280,
  12. })
  13. const isMobile = computed(() => breakpoints.isSmaller('tablet'))
  14. const slots = useSlots();
  15. const titleNode = computed(() => {
  16. return slots.title ? slots.title()?.[0] : title.value ? h("h1", {}, title.value) : null;
  17. });
  18. </script>
  19. <template>
  20. <div class="home-section">
  21. <component :is="titleNode" class="title" />
  22. <el-row class="content" justify="center" :gutter="isMobile ? 8 : 20" tag="section" v-bind="$attrs">
  23. <slot></slot>
  24. </el-row>
  25. </div>
  26. </template>
  27. <style lang="scss" scoped>
  28. @use '@/.vitepress/theme/screen' as *;
  29. .home-section {
  30. display: flex;
  31. flex-direction: column;
  32. align-items: center;
  33. width: 100%;
  34. gap: 20px;
  35. }
  36. .title {
  37. text-wrap: nowrap;
  38. @include breakpoint(mobile) {
  39. width: 100%;
  40. padding-left: 10px;
  41. font-size: 16px;
  42. line-height: 16px;
  43. }
  44. }
  45. .content {
  46. width: 100%;
  47. }
  48. .el-row {
  49. row-gap: 20px;
  50. align-items: stretch;
  51. }
  52. </style>