maroo
maroo
NNuxt
Created by maroo on 9/11/2024 in #❓・help
Is it safe to use useFetch() inside a function?
I think useFetch, while being a macro, is named like a composable that can be used anywhere within the setup context. Since the official documentation doesn’t emphasize important caveats, it’s an easy trap to fall into.
6 replies
NNuxt
Created by maroo on 9/11/2024 in #❓・help
Is it safe to use useFetch() inside a function?
The information presented in the video is absolutely correct. However, I believe that consistently using useFetch for all data fetching and posting would enhance readability and improve error handling. As you may know, when using $fetch, it becomes difficult to perform early returns when handling errors with the .catch() chain, often leading to a larger try...catch. When wrapped in a catch, it’s harder to specifically detect and handle other errors, requiring the import and casting of types like IFetchError for more accurate error handling.
6 replies
NNuxt
Created by Tony on 6/4/2024 in #❓・help
useFetch refresh failing to recognise new query params
You'll also need to add page meta.
definePageMeta({
key: (route) => route.fullPath
})
definePageMeta({
key: (route) => route.fullPath
})
7 replies
NNuxt
Created by Tony on 6/4/2024 in #❓・help
useFetch refresh failing to recognise new query params
const route = useRoute()
const { data, refresh } = await useFetch(`/api/images`, {
query: {
q: query
},
key: route.fullPath
});
const route = useRoute()
const { data, refresh } = await useFetch(`/api/images`, {
query: {
q: query
},
key: route.fullPath
});
add key to prevent the response being cached.
7 replies