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

CharacterList.vue

40 lines1.3 KB

1<script setup lang="ts">
2import { useQueries } from '@tanstack/vue-query'
3import { charactersQueries } from './services/characters/queries'
4​
5const props = defineProps<{ ids: Array<number> }>()
6​
7const characters = useQueries({
8 queries: () => props.ids.map((id) => charactersQueries.detail(id)),
9})
10</script>
11​
12<template>
13 <template v-for="(character, index) in characters" :key="index">
14 <template v-if="character.status === 'pending'">Loading...</template>
15 <template v-else-if="character.status === 'error'">Error...</template>
16 <template v-else-if="character.data === null">Not found ...</template>
17 <div v-else style="display: flex">
18 <img
19 width="100"
20 height="100"
21 :alt="character.data.image"
22 :src="character.data.image"
23 />
24 <div style="padding-left: 10px; text-align: left">
25 <h5 style="margin-top: 0; margin-bottom: 5px">
26 {{ character.data.name }} (#{{ character.data.id }})
27 </h5>
28 <p style="margin-top: 0; margin-bottom: 2px">
29 Status: {{ character.data.status }}
30 </p>
31 <p style="margin-top: 0; margin-bottom: 2px">
32 Species: {{ character.data.species }}
33 </p>
34 <p style="margin-top: 0; margin-bottom: 2px">
35 Gender: {{ character.data.gender }}
36 </p>
37 </div>
38 </div>
39 </template>
40</template>