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

main.ts

26 lines759 Bytes

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