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

App.vue

48 lines1.4 KB

1<script lang="ts">
2import { defineComponent, ref } from 'vue'
3​
4import Posts from './Posts.vue'
5import Post from './Post.vue'
6​
7export default defineComponent({
8 name: 'App',
9 components: { Posts, Post },
10 setup() {
11 const visitedPosts = ref(new Set())
12 const isVisited = (id: number) => visitedPosts.value.has(id)
13​
14 const postId = ref(-1)
15 const setPostId = (id: number) => {
16 visitedPosts.value.add(id)
17 postId.value = id
18 }
19​
20 return {
21 isVisited,
22 postId,
23 setPostId,
24 }
25 },
26})
27</script>
28​
29<template>
30 <h1>Vue Query - Dependent Queries</h1>
31 <p>
32 As you visit the posts below, you will notice them in a loading state the
33 first time you load them. However, after you return to this list and click
34 on any posts you have already visited again, you will see them load
35 instantly and background refresh right before your eyes!
36 <br />
37 You will also notice, that after some time the name of the author gets
38 loaded. This Data is not directly included in the
39 <code>/post/id</code> response but gets fetched when the post gets loaded
40 from its <code>userId</code>.
41 <strong>
42 (You may need to throttle your network speed to simulate longer loading
43 sequences)
44 </strong>
45 </p>
46 <Post v-if="postId > -1" :postId="postId" @setPostId="setPostId" />
47 <Posts v-else :isVisited="isVisited" @setPostId="setPostId" />
48</template>