DataTableComponent.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <v-col
  3. cols="12"
  4. sm="12"
  5. >
  6. <v-data-table
  7. :headers="headers"
  8. :items="entries"
  9. :options.sync="options"
  10. :server-items-length="totalEntries"
  11. :loading="loading"
  12. class="elevation-1"
  13. ></v-data-table>
  14. </v-col>
  15. </template>
  16. <script lang="ts">
  17. import {defineComponent, ref, useContext, useFetch} from '@nuxtjs/composition-api'
  18. import {Collection, Model, Repository} from "@vuex-orm/core";
  19. import personActivitiesData from '@/data/personActivitiesData'
  20. export default defineComponent({
  21. props: {
  22. repository:{
  23. type: Object as () => Repository,
  24. required: true
  25. },
  26. uri:{
  27. type: String,
  28. required: true
  29. },
  30. headers:{
  31. type: Array,
  32. required: true
  33. }
  34. },
  35. setup({repository, uri}) {
  36. const totalEntries = ref(0)
  37. const entries = ref([] as Collection<Model>)
  38. const loading = ref(true)
  39. const options = ref({})
  40. const {$http} = useContext()
  41. const {fetch, fetchState} = useFetch(async ()=>{
  42. const collection:{ [key:string]: any} = await $http.$get(`https://local.new.api.opentalent.fr/api/${uri}`)
  43. repository.insert(collection['hydra:member']);
  44. entries.value = repository.all()
  45. totalEntries.value = parseInt(collection['hydra:totalItems'])
  46. loading.value = false
  47. })
  48. return {
  49. entries,
  50. totalEntries,
  51. loading,
  52. options
  53. }
  54. }
  55. })
  56. </script>