Open History to see the last commit
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 - Basic</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 <strong>
37 (You may need to throttle your network speed to simulate longer loading
38 sequences)
39 </strong>
40 </p>
41 <Post v-if="postId > -1" :postId="postId" @setPostId="setPostId" />
42 <Posts v-else :isVisited="isVisited" @setPostId="setPostId" />
43</template>