Questions about data fetching #20885
Replies: 2 comments 2 replies
-
I can really second that. Nuxt's data fetching part in general is really confusing at this time and not intuitive at all (even though Nuxt claims to be the "The Intuitive Web Framework" )... In addition to your 2 points I want to point out the following:
function useAsyncData(
handler: (nuxtApp?: NuxtApp) => Promise<DataT>,
options?: AsyncDataOptions<DataT>
): AsyncData<DataT>
function useAsyncData(
key: string,
handler: (nuxtApp?: NuxtApp) => Promise<DataT>,
options?: AsyncDataOptions<DataT>
): Promise<AsyncData<DataT>>
|
Beta Was this translation helpful? Give feedback.
-
|
Beta Was this translation helpful? Give feedback.
-
I've been reading docs and making small project to understand Nuxt3. It was working good until data-fetching.
I've got two questions.
First, what is difference between
refresh
andexecute
method? I read UseAsyncData docs and I don't really understand the reason whyexecute
andrefresh
method exist together. The docs saysrefresh/execute: a function that can be used to refresh the data returned by the handler function
and asyncData.d.ts says
It looks like the same method. I tried to use them in many cases, I couldn't find any differences. My conclusion was those are the same and interchangeable. Is there any differences?
Second, I made a reproduction.
When
useAsyncData
withimmediate: false
option and fetch data by clicking button, it loads data on client-side.However, when I move to other page and come back, the data is still alive because it's cached so
useAsyncData
doesn't make api call. I expected that if I move to other page,data
variable is undefined.I read docs about data-fetching and refreshNuxtData.
UseAsyncData
docs saysI understood that it is just for
de-duplicated across requests
between server and client but I guess I'm wrong.The question is that if I want to get new data whenever client-side navigation occurs and data fetching key is just same like
board/list
andboard/detail/1
, I always have to clear the data manually for all components? is there any option for that?Beta Was this translation helpful? Give feedback.
All reactions