index.vue 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <main>
  3. <p>Nom : {{ country }}</p>
  4. <div>
  5. <button @click="fetchPrevious">Previous</button>
  6. <button @click="fetchNext">Next</button>
  7. </div>
  8. <nuxt-link to="/form">Edit</nuxt-link>
  9. </main>
  10. </template>
  11. <script setup lang="ts">
  12. import {useEntityManager} from "~/composables/data/useEntityManager";
  13. import {Ref} from "@vue/reactivity";
  14. import {Country} from "~/models/Core/Country";
  15. import ApiResource from "~/models/ApiResource";
  16. const id: Ref<number> = ref(2)
  17. const em = useEntityManager()
  18. const country: Ref<ApiResource | null> = ref(null)
  19. const fetchCountry = async function () {
  20. console.log('fetch ', id.value)
  21. country.value = await em.fetch(Country, id.value)
  22. }
  23. await fetchCountry()
  24. const fetchNext = () => {
  25. id.value += 1
  26. console.log('next')
  27. fetchCountry()
  28. }
  29. const fetchPrevious = async function () {
  30. id.value -= 1
  31. console.log('previous')
  32. await fetchCountry()
  33. }
  34. </script>
  35. <style>
  36. a {
  37. color: blue;
  38. }
  39. a:hover {
  40. text-decoration: underline;
  41. }
  42. button {
  43. border: grey solid 1px;
  44. padding: 5px;
  45. margin: 5px;
  46. }
  47. button:hover {
  48. text-decoration: underline;
  49. }
  50. button:focus {
  51. background-color: lightgrey;
  52. }
  53. </style>