How do you refresh a fetch with a dynamic path (/api/page/[id])
I have a hard time understanding that doc https://nuxt.com/docs/getting-started/data-fetching#computed-url
Basically I have a fetch
{data, refresh} = useFetch("/api/${dynamicID}")
(<- I know it’s suposed to be )
but when I refresh the dynamicID doesn’t change which is normal... but what’s the workaround (note that I can’t use
watch because it’s on
immediate: false` and I need to refresh it on cue) ?Nuxt
Data fetching · Get Started with Nuxt
Nuxt provides composables to handle data fetching within your application.
8 Replies
what's
dynamicID
?it’s an url parameter /api/[id].ts
(and a ref in the component)
u'd do something like
yeah but it doesn’t work on refresh
whatever value is set when the component is instanciated will be triggered
I think useAsyncData would do the trick, where your call function uses what Cake commented here earlier
I haven’t tried useAsync yet but ()=> doesn’t change the outcome
You're doing
useFetch("/api/${dynamicID}")
whilst claiming dynamicId
is a ref. That means it should be:
But you're stating this doesn't change the outcome.
You also mention the presence of immediate: false
, and later state it does not work on refresh – which is expected behaviour?
Can you provide more input here? Possible a repro @ https://nuxt.new?Alternately, take advantage of https://nuxt.com/docs/api/utils/refresh-nuxt-data