File: basic.md | Updated: 11/15/2025
Search...
+ K
Auto
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples GitHub Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Docs Examples Github Contributors
Maintainers Partners Support Learn StatsBETA Discord Merch Blog GitHub Ethos Brand Guide
Documentation
Framework
Vue
Version
Latest
Search...
+ K
Menu
Getting Started
Guides & Concepts
API Reference
ESLint
Examples
Plugins
Framework
Vue
Version
Latest
Menu
Getting Started
Guides & Concepts
API Reference
ESLint
Examples
Plugins
Vue Example: Basic
=================================================================================================================================================================================================================================================================================================================================================================================
Code ExplorerCode
Interactive SandboxSandbox
src
App.vue
Post.vue
Posts.vue
main.ts
shims-vue.d.ts
types.d.ts
.gitignore
README.md
index.html
package.json
tsconfig.json
vite.config.ts
vue
<script lang="ts">
import { defineComponent, ref } from 'vue'
import { VueQueryDevtools } from '@tanstack/vue-query-devtools'
import Posts from './Posts.vue'
import Post from './Post.vue'
export default defineComponent({
name: 'App',
components: { Posts, Post, VueQueryDevtools },
setup() {
const visitedPosts = ref(new Set())
const isVisited = (id: number) => visitedPosts.value.has(id)
const postId = ref(-1)
const setPostId = (id: number) => {
visitedPosts.value.add(id)
postId.value = id
}
return {
isVisited,
postId,
setPostId,
}
},
})
</script>
<template>
<h1>Vue Query - Basic</h1>
<p>
As you visit the posts below, you will notice them in a loading state the
first time you load them. However, after you return to this list and click
on any posts you have already visited again, you will see them load
instantly and background refresh right before your eyes!
<strong>
(You may need to throttle your network speed to simulate longer loading
sequences)
</strong>
</p>
<Post v-if="postId > -1" :postId="postId" @setPostId="setPostId" />
<Posts v-else :isVisited="isVisited" @setPostId="setPostId" />
<VueQueryDevtools />
</template>
<script lang="ts">
import { defineComponent, ref } from 'vue'
import { VueQueryDevtools } from '@tanstack/vue-query-devtools'
import Posts from './Posts.vue'
import Post from './Post.vue'
export default defineComponent({
name: 'App',
components: { Posts, Post, VueQueryDevtools },
setup() {
const visitedPosts = ref(new Set())
const isVisited = (id: number) => visitedPosts.value.has(id)
const postId = ref(-1)
const setPostId = (id: number) => {
visitedPosts.value.add(id)
postId.value = id
}
return {
isVisited,
postId,
setPostId,
}
},
})
</script>
<template>
<h1>Vue Query - Basic</h1>
<p>
As you visit the posts below, you will notice them in a loading state the
first time you load them. However, after you return to this list and click
on any posts you have already visited again, you will see them load
instantly and background refresh right before your eyes!
<strong>
(You may need to throttle your network speed to simulate longer loading
sequences)
</strong>
</p>
<Post v-if="postId > -1" :postId="postId" @setPostId="setPostId" />
<Posts v-else :isVisited="isVisited" @setPostId="setPostId" />
<VueQueryDevtools />
</template>
[###### Want to Skip the Docs?
Query.gg - The Official React Query Course
\
“If you’re serious about *really* understanding React Query, there’s no better way than with query.gg”—Tanner Linsley
Learn More](https://query.gg/?s=tanstack)
