Replies: 3 comments 1 reply
-
I solved it by using const queries = computed(() => {
return [
{
queryKey: ['project', projectId.value],
queryFn: () => useFetch<Project>(`/v1/projects/${projectId.value}`),
},
]
})
const projectQueries = useQueries({ queries: queries })
const isLoading = computed(() => projectQueries[0].isLoading)
const isError = computed(() => projectQueries[0].isError)
`` |
Beta Was this translation helpful? Give feedback.
-
I think that If const projectId = ref('ID');
const { isLoading, isError } = useProject(projectId) and inside const useProject = (id: Ref<string>) => {
return useQuery({
queryKey: ['project', { id }],
queryFn: () => useFetch<Project>(`/v1/projects/${id.value}`),
})
} |
Beta Was this translation helpful? Give feedback.
-
I need an elegant solution for this issue too. <RouterView v-slot="{ Component, route }">
<component
:is="Component"
:key="route.params.id"
/>
</RouterView> However, I am wondering if this is the right approach. No other proposals are working for me because the setup function only gets triggered on the initial load. When I use the returned refetch method in the onUpdated hook, the queryFn triggers but the queryKey remains unchanged, regardless of whether the id element in the key array is reactive or not. Consequently, the query always returns the same object with the same id as it did on the first load. I would prefer not to rerender the component, as that doesn't seem like the correct approach. Ideally, the refetch method could perhaps take an argument with the updated key, which we could then use in the onUpdated hook. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I'm just implementing TanStack-Query into my project and having some issues to solve the following situation:
I use nested routes with vue-router to get something like this url structure and their components:
project/:id
=>ProjectView
project/:id/dashboard
=>ProjectDashboardView
project/:id/settings
=>ProjectSettingsView
If the project id changes, vue-router will use the same component and just update it. So the setup function is not called.
How do I update the query inside and keep the reactivity?
Or do I have to move the LoadingView to every child component (because they are recreated every time) or emit events from the child component to the parent component?
Beta Was this translation helpful? Give feedback.
All reactions