Open History to see the last commit
1<script lang="ts">
2import { defineComponent, ref } from 'vue'
3import { VueQueryDevtools } from '@tanstack/vue-query-devtools'
4β
5import Posts from './Posts.vue'
6import Post from './Post.vue'
7β
8export default defineComponent({
9 name: 'App',
10 components: { Posts, Post, VueQueryDevtools },
11 setup() {
12 const visitedPosts = ref(new Set())
13 const isVisited = (id: number) => visitedPosts.value.has(id)
14β
15 const postId = ref(-1)
16 const setPostId = (id: number) => {
17 visitedPosts.value.add(id)
18 postId.value = id
19 }
20β
21 return {
22 isVisited,
23 postId,
24 setPostId,
25 }
26 },
27})
28</script>
29β
30<template>
31 <h1>Vue Query - Basic</h1>
32 <p>
33 As you visit the posts below, you will notice them in a loading state the
34 first time you load them. However, after you return to this list and click
35 on any posts you have already visited again, you will see them load
36 instantly and background refresh right before your eyes!
37 <strong>
38 (You may need to throttle your network speed to simulate longer loading
39 sequences)
40 </strong>
41 </p>
42 <Post v-if="postId > -1" :postId="postId" @setPostId="setPostId" />
43 <Posts v-else :isVisited="isVisited" @setPostId="setPostId" />
44 <VueQueryDevtools />
45</template>