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

background-fetching-indicators.md

45 lines983 Bytes

1---
2id: background-fetching-indicators
3title: Background Fetching Indicators
4ref: docs/framework/react/guides/background-fetching-indicators.md
5---
6​
7[//]: # 'Example'
8​
9```vue
10<script setup>
11import { useQuery } from '@tanstack/vue-query'
12​
13const { isPending, isFetching, isError, data, error } = useQuery({
14 queryKey: ['todos'],
15 queryFn: getTodos,
16})
17</script>
18​
19<template>
20 <div v-if="isFetching">Refreshing...</div>
21 <span v-if="isPending">Loading...</span>
22 <span v-else-if="isError">Error: {{ error.message }}</span>
23 <!-- We can assume by this point that `isSuccess === true` -->
24 <ul v-else-if="data">
25 <li v-for="todo in data" :key="todo.id">{{ todo.title }}</li>
26 </ul>
27</template>
28```
29​
30[//]: # 'Example'
31[//]: # 'Example2'
32​
33```vue
34<script setup>
35import { useIsFetching } from '@tanstack/vue-query'
36​
37const isFetching = useIsFetching()
38</script>
39​
40<template>
41 <div v-if="isFetching">Queries are fetching in the background...</div>
42</template>
43```
44​
45[//]: # 'Example2'