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

PostDetail.vue

32 lines834 Bytes

1<script setup lang="ts">
2import { useQuery } from '@tanstack/vue-query'
3import { postsQueries } from './services/posts/queries'
4​
5const props = defineProps<{ postId: number }>()
6defineEmits<{ setPostId: [id: number] }>()
7​
8const { isPending, isError, isFetching, data, error } = useQuery(() =>
9 postsQueries.detail(props.postId),
11</script>
12​
13<template>
14 <h1>Post {{ postId }}</h1>
15 <a href="#" @click="$emit('setPostId', -1)"> Back </a>
16 <div v-if="isPending" class="update">Loading...</div>
17 <div v-else-if="isError">An error has occurred: {{ error }}</div>
18 <div v-else-if="data">
19 <h1>{{ data.title }}</h1>
20 <div>
21 <p>{{ data.body }}</p>
22 </div>
23 <div v-if="isFetching" class="update">Background Updating...</div>
24 </div>
25</template>
26​
27<style scoped>
28.update {
29 font-weight: bold;
30 color: green;
32</style>