Query Docs
Examples
- Basic
- Vue 2.6
- Vue 2.7
- Nuxt 3
- Persister
- Basic w/ GraphQL-Request
- Default Query Function
- Playground
- Algolia
- Shadow DOM
- Devtools Embedded Panel
- Chat example (streaming)
- Star Wars
- Rick And Morty
- Vue Router
- Offline Queries and Mutations
- Suspense
- Batching
- Auto Refetching / Polling / Realtime
- Optimistic Updates
- Pagination
- Load-More & Infinite Scroll
- Infinite query with Max pages
- Prefetching
Vue Example: Batching
<script setup lang="ts">
import { ref } from 'vue'
import { VueQueryDevtools } from '@tanstack/vue-query-devtools'
import Characters from './Characters.vue'
const ids = ref<Array<number>>([])
const idsToLoad = ref<Array<number>>([])
const error = ref('')
const handleInput = (event: Event) => {
const parsedIds = (event.target as HTMLInputElement).value
.split(',')
.map((id) => id.trim())
if (parsedIds.every((id) => /^\d+$/.test(id))) {
ids.value = parsedIds.map(Number)
error.value = ''
} else {
error.value = 'Invalid.. only use numbers and comma'
}
}
</script>
<template>
<div class="App">
<h2>Character fetcher</h2>
<div>
<label for="ids" style="display: block">
Character ids (numeric, comma separated)
</label>
<input
id="ids"
style="display: inline-block"
placeholder="ids"
@input="handleInput"
/>
</div>
<h3 v-if="error" style="color: red">{{ error }}</h3>
<button type="button" :disabled="!!error" @click="idsToLoad = ids">
Load characters
</button>
<div>
<h4 style="text-align: left">Characters:</h4>
<Characters :ids="idsToLoad" />
</div>
</div>
<VueQueryDevtools initialIsOpen />
</template>