index.vue 1.3 KB

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