index.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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-show="postList?.items.length === 0"
  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. <BlogPost
  20. v-show="postList?.items.length > 0"
  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. </div>
  31. </template>
  32. <script setup lang="ts">
  33. import type { TPosts } from '~/types/posts'
  34. definePageMeta({
  35. name: 'Блог',
  36. middleware: ['user-only'],
  37. })
  38. const { $api } = useNuxtApp()
  39. const postList = ref<TPosts>({
  40. items: []
  41. })
  42. onMounted(async () => {
  43. postList.value = await $api.blog.getPosts()
  44. })
  45. </script>