useFetch with url function does not re-fetch data
See original GitHub issueEnvironment
Nuxt CLI v3.0.0-rc.8 13:40:47 Nuxt project info: 13:40:49
- Operating System:
Linux
- Node Version:
v18.6.0
- Nuxt Version:
3.0.0-rc.8
- Package Manager:
yarn@1.22.19
- Builder:
vite
- User Config:
build
,buildModules
,runtimeConfig
- Runtime Modules:
-
- Build Modules:
@nuxtjs/tailwindcss@5.3.2
Reproduction
components/ProjectName.vue:
<template>
<span>
{{props.projectId}}
<span>{{project}}</span>
</span>
</template>
<script setup>
const props = defineProps({
projectId: String
})
const projectId = ref(props.projectId)
const { data: project, pending, refresh } = await useFetch(
() => {
const url = '/api/projects/' + projectId.value;
console.log(url);
return url
}, {
headers: useRequestHeaders(['cookie']),
watch: [projectId],
lazy: false,
cache: false
})
</script>
pages/[projectId].vue
<template>
<ProjectName :projectId=$route.params.projectId />
</template>
Describe the bug
If “projectId” prop of the ProjectName.vue component changes, the useFetch url() generation function is called and writes the new url via console.log(url) to console. However, no new data is fetched from the backend.
Additional context
Might be related to https://github.com/nuxt/framework/issues/6273
Logs
No response
Issue Analytics
- State:
- Created a year ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
useFetch do not refetch data when use Dynamic Routes #6604
useFetch do not refetch data when use Dynamic Routes #6604 ... dynamic route should be a function that returns a string. const {...
Read more >useFetch
Need to fetch some data? Try this one out. It's an isomorphic fetch hook. That means it works with SSR (server side rendering)....
Read more >Custom useFetch Hook not working after url state change
Here is the first component that calls useFetch effectively and returns data: const ArtistDeck = (props) => { // props.apiRequest is a ...
Read more >useFetch - VueUse
Reactive Fetch API provides the ability to abort requests, intercept requests before they are fired, automatically refetch requests when the url changes, and ......
Read more >useFetch() react hook - usehooks-ts
The fetch is executed when the component is mounted and if the url changes. ... is unmounted before the data is recovered, the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@bf You might consider a shorter “workaround” with useFetch. Adding the key made it work in my case at least. 😃
But agreed the documentation says it should refresh using a function
const { data } = await useFetch('/api/projects/' + projectId.value, { key: projectId.value });
nice