Open History to see the last commit
1<script setup lang="ts">
2import { ref } from 'vue'
3import PostDetail from './PostDetail.vue'
4import PostList from './PostList.vue'
5β
6const postId = ref(-1)
7const setPostId = (id: number) => {
8 postId.value = id
9}
10</script>
11β
12<template>
13 <h1>Vue Query - Dependent Queries</h1>
14 <p>
15 As you visit the posts below, you will notice them in a loading state the
16 first time you load them. However, after you return to this list and click
17 on any posts you have already visited again, you will see them load
18 instantly and background refresh right before your eyes!
19 <br />
20 You will also notice, that after some time the name of the author gets
21 loaded. This data is not directly included in the
22 <code>/posts/id</code> response but gets fetched when the post gets loaded
23 from its <code>userId</code>.
24 <strong>
25 (You may need to throttle your network speed to simulate longer loading
26 sequences)
27 </strong>
28 </p>
29 <PostDetail v-if="postId > -1" :post-id="postId" @set-post-id="setPostId" />
30 <PostList v-else @set-post-id="setPostId" />
31</template>