index.vue 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. <template>
  2. <div class="w-full overflow-y-scroll flex flex-col p-2 gap-5">
  3. <div
  4. v-if="newsList === null"
  5. class="w-full h-full"
  6. >
  7. <div
  8. v-for="i of Array.from({ length: 10 }).map((i, idx) => idx)"
  9. :key="i"
  10. :class="i === 0 ? 'mt-0 mb-4' : 'my-4'"
  11. class="w-full h-64 loading rounded-md opacity-30"
  12. />
  13. </div>
  14. <template v-else>
  15. <WallPost
  16. v-for="news in newsList"
  17. :key="news.id"
  18. :image="news.preview.length > 0 ? news.preview : `/nophoto.png`"
  19. :title="news.title"
  20. :description="news.description"
  21. :date="news.date"
  22. @click="navigateTo(`/news/${news.id}`)"
  23. />
  24. </template>
  25. </div>
  26. </template>
  27. <script setup lang="ts">
  28. interface NewsList {
  29. id: number
  30. date: string
  31. title: string
  32. description: string
  33. preview: string
  34. type: string
  35. }
  36. definePageMeta({
  37. name: 'Новости',
  38. middleware: ['user-only'],
  39. })
  40. const api = useApi()
  41. const newsList = ref<NewsList | null>(null)
  42. onMounted(async () => {
  43. newsList.value = await api.get('/news/')
  44. })
  45. </script>