T
TanStack•3y ago
conventional-tan

Usage from within a Vue plugin

I am looking to create a Vue plugin that needs to be able to access the cache and refetch if necessary. Is this even possible considering useQuery can only be used in a setup function?
4 Replies
exotic-emerald
exotic-emerald•3y ago
It's possible. You have to create QueryClient manually and then pass it to both your pluging and VueQueryPlugin as an option. Notice that with this solution you might sometimes experience weirdness when HMR updates modules.
conventional-tan
conventional-tanOP•3y ago
Thanks for the response! Sorry I've looked through the docs on QueryClient and I don't quite understand your solution. Is there an example of this in the docs? Or would you mind providing a small code sample of how this might look?
exotic-emerald
exotic-emerald•3y ago
https://github.com/TanStack/query/blob/main/docs/vue/guides/custom-client.md Not sure why it's not hooked up to the docs though 😄
conventional-tan
conventional-tanOP•3y ago
Thats great. Thanks!

Did you find this page helpful?