index.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <template>
  2. <div class="w-full overflow-y-scroll flex flex-col p-2 gap-5 mb-[100px]">
  3. <!-- <NuxtLink to="/blog/new">
  4. <button class="absolute bottom-5 right-5 bg-primary hover:opacity-50 p-4 z-20 rounded-full flex items-center justify-center duration-150">
  5. <IPencil class="w-10 h-10" />
  6. </button>
  7. </NuxtLink> -->
  8. <div
  9. v-if="!postList"
  10. class="w-full h-full"
  11. >
  12. <div
  13. v-for="i of Array.from({ length: 10 }).map((i, idx) => idx)"
  14. :key="i"
  15. :class="i === 0 ? 'mt-0 mb-4' : 'my-4'"
  16. class="w-full h-32 loading rounded-md opacity-30"
  17. />
  18. </div>
  19. <template v-else>
  20. <BlogPost
  21. v-for="(post, idx) in postList.items"
  22. :key="idx"
  23. :avatar="post.avatar"
  24. :title="post.title"
  25. :raw_content="post.raw_content"
  26. :date="post.date"
  27. :author="post.author"
  28. :attachments="post.attachments"
  29. />
  30. </template>
  31. </div>
  32. </template>
  33. <script setup lang="ts">
  34. import type { TPosts } from '~/types/posts'
  35. definePageMeta({
  36. name: 'Блог',
  37. middleware: ['user-only'],
  38. })
  39. const { $api } = useNuxtApp()
  40. const postList = ref<TPosts>()
  41. onMounted(async () => {
  42. postList.value = await $api.blog.getPosts()
  43. })
  44. </script>