How to force a page to perform API calls #9936
Unanswered
agiovinazzi
asked this question in
Help/Questions
Replies: 1 comment 4 replies
-
Hi @agiovinazzi, there are different ways to do that depending on the context. Since you're not server-side rendering and you don't need to de-duplicate requests across server and client, the most straightforward would be to use $fetch in a top-level await: data.value = await $fetch('https://jsonplaceholder.typicode.com/comments') Nuxt will show the loading indicator until that call is completed and then complete the navigation. Another way to get the same outcome without sacrificing the const { data } = await useFetch('https://jsonplaceholder.typicode.com/comments', {
getCachedData() {
return null
}
}) Bear in mind that this only works with Nuxt >= 3.8. |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hi everyone, First of all, I apologize for any inaccuracies in my question. I'm getting back to the frontend after a few years.
I'm building a management system with Vue 3 and Nuxt 3. On some pages, I would need calls to the backend to be made every time for each visit (both on refresh of the page and clicking on the menu links that open it).
I currently have calls in onMounted(), I use useFetch() to make them, and server-side rendering is disabled.
Currently, when I open the page the "first" time, it makes calls regularly, then I go to a second page, but if I return to the first, it keeps the data in cache. Instead, I would like it to redo all the calls on that particular page.
I hope that my question is clear.
Thanks in advance!
Beta Was this translation helpful? Give feedback.
All reactions