avalanche
avalanche
NNuxt
Created by avalanche on 10/10/2024 in #❓・help
Same useLazyAsyncData and useFetch - but useLazyAsyncData not fetch on initial render or hard refres
const {
status,
data: airlines,
error,
refresh
} = useFetch('/api/airlines/list', {
lazy: true,
params: queryItems,
transform: (airlines: ListResult<Airline>) => transformer(airlines)
})

const {
status,
data: airlines,
error,
refresh
} = await useLazyAsyncData(
'airlines',
() =>
$fetch('/api/airlines/list', {
params: queryItems
}),
{
transform: (airlines: ListResult<Airline>) => transformer(airlines)
}
)
const {
status,
data: airlines,
error,
refresh
} = useFetch('/api/airlines/list', {
lazy: true,
params: queryItems,
transform: (airlines: ListResult<Airline>) => transformer(airlines)
})

const {
status,
data: airlines,
error,
refresh
} = await useLazyAsyncData(
'airlines',
() =>
$fetch('/api/airlines/list', {
params: queryItems
}),
{
transform: (airlines: ListResult<Airline>) => transformer(airlines)
}
)
I have those two functions and I think they are the same? But for some reason the useLazyAsyncData doesn't seem to make the api call on initial load - it will if I navigate away and navigate back. Any thoughts on what I am doing wrong?
3 replies