Open History to see the last commit
1<script lang="ts">
2import { defineComponent, ref } from '@vue/composition-api'
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 <div>
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 </div>
45</template>