Collection.vue 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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="{ 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. },
  33. loaderType: {
  34. type: String,
  35. required: false,
  36. default: 'text',
  37. },
  38. newLink: {
  39. type: String,
  40. required: false,
  41. },
  42. })
  43. const { model, parent }: ToRefs = toRefs(props)
  44. const { fetchCollection } = useEntityFetch()
  45. const { data: collection, pending } = fetchCollection(model.value, parent.value)
  46. </script>