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