Vue 3 setup API Tanstack Query with params not refetching data
Hi everyone could anyone help me with Vue3 Tanstack Query usage I've went through the docs and tried applying data refetch on parameter change but for some reason the api call is not being triggered... Any ideas?
4 Replies
stormy-goldOP•2y ago
Even if I wrap date ref with computed property the issue is still the same the date has correct values but new API call is not being made
rising-crimson•2y ago
You're losing reactivity in your
queryKey
, by unwrapping it with .value
access. Change that to queryKey: ["energy", date]
, so that vue-query can detect that value of date ref has changed.
Also not sure if it's just a typo here but you're not returning fetchEnergyData
promise in queryFn
.stormy-goldOP•2y ago
yes you are right about query key I had to remove .value... Not sure why though since the value property is being changed.
queryFn is an arrow function so I don't need to return it?
fascinating-indigo•2y ago
There's no compiler magic happening with Vue query so it has no way of tracking the .value changing so you have to pass a ref or wrap the whole thing in computed()