Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

main.ts

27 lines760 Bytes

1import { createApp } from 'vue'
2import { VueQueryPlugin } from '@tanstack/vue-query'
3​
4import App from './App.vue'
5import type { QueryKey } from '@tanstack/vue-query'
6​
7// Define a default query function that will receive the query key
8const defaultQueryFn = async ({ queryKey }: { queryKey: QueryKey }) => {
9 const response = await fetch(
10 `https://jsonplaceholder.typicode.com${queryKey[0]}`,
11 )
12 if (!response.ok) throw new Error('Failed to fetch data')
13 return await response.json()
15​
16createApp(App)
17 // provide the default query function to your app via the query client
18 .use(VueQueryPlugin, {
19 queryClientConfig: {
20 defaultOptions: {
21 queries: {
22 queryFn: defaultQueryFn,
23 },
24 },
25 },
26 })
27 .mount('#app')