Collection.vue 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <!-- Permet de requêter une subResource et de donner son contenu à un slot -->
  2. <template>
  3. <main>
  4. <v-skeleton-loader v-if="pending" :type="loaderType" />
  5. <div v-else>
  6. <!-- Content -->
  7. <slot name="list.item" v-bind="{ items: collection?.items }" />
  8. <!-- New button -->
  9. <v-btn v-if="newLink" class="theme-primary float-right">
  10. <NuxtLink :to="newLink" class="no-decoration">
  11. <v-icon>fa-plus-circle</v-icon>
  12. <span>{{ $t('add') }}</span>
  13. </NuxtLink>
  14. </v-btn>
  15. </div>
  16. <slot />
  17. </main>
  18. </template>
  19. <script setup lang="ts">
  20. import { computed, toRefs } from 'vue'
  21. import type { ComputedRef, ToRefs } from 'vue'
  22. import { useEntityFetch } from '~/composables/data/useEntityFetch'
  23. import type { Collection } from '~/types/data'
  24. const props = defineProps({
  25. model: {
  26. type: Object,
  27. required: true,
  28. },
  29. parent: {
  30. type: Object,
  31. required: false,
  32. default: () => null,
  33. },
  34. loaderType: {
  35. type: String,
  36. required: false,
  37. default: 'text',
  38. },
  39. newLink: {
  40. type: String,
  41. required: false,
  42. default: null,
  43. },
  44. })
  45. const { model, parent }: ToRefs = toRefs(props)
  46. const { fetchCollection } = useEntityFetch()
  47. const { data: collection, pending } = fetchCollection(model.value, parent.value)
  48. </script>