Open History to see the last commit
1---
2id: default-query-function
3title: Default Query Function
4ref: docs/framework/react/guides/default-query-function.md
5---
6β
7[//]: # 'Example'
8β
9```tsx
10// Define a default query function that will receive the query key
11const defaultQueryFn = async ({ queryKey }) => {
12 const { data } = await axios.get(
13 `https://jsonplaceholder.typicode.com${queryKey[0]}`,
14 )
15 return data
16}
17β
18// provide the default query function to your app with defaultOptions
19const vueQueryPluginOptions: VueQueryPluginOptions = {
20 queryClientConfig: {
21 defaultOptions: { queries: { queryFn: defaultQueryFn } },
22 },
23}
24app.use(VueQueryPlugin, vueQueryPluginOptions)
25β
26// All you have to do now is pass a key!
27const { status, data, error, isFetching } = useQuery({
28 queryKey: [`/posts/${postId}`],
29})
30```
31β
32[//]: # 'Example'