index.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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 === null"
  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-64 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. interface PostList {
  35. title: string
  36. avatar: string
  37. author: string
  38. date: string
  39. raw_content: string
  40. attachments: []
  41. }
  42. definePageMeta({
  43. name: 'Блог',
  44. middleware: ['user-only'],
  45. })
  46. const api = useApi()
  47. const postList = ref<{ items: PostList[] } | null>(null)
  48. onMounted(async () => {
  49. postList.value = await api.get('/blogs/')
  50. })
  51. </script>