-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathSectionList.vue
56 lines (48 loc) · 1.08 KB
/
SectionList.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
<template>
<h2>Sections</h2>
<div v-if="loading">Loading...</div>
<div v-else-if="error">Error: {{ error.message }}</div>
<div v-else-if="noSections">This chapter has no sections</div>
<ul v-else>
<li v-for="section of sections" :key="section.id">
{{ section.number }}. {{ section.title }}
</li>
</ul>
</template>
<script>
import { useQuery, useResult } from '@vue/apollo-composable'
import { gql } from '@apollo/client/core'
import { computed } from 'vue'
export default {
name: 'SectionList',
props: {
id: {
type: Number,
required: true
}
},
setup(props) {
const { result, loading, error } = useQuery(
gql`
query SectionList($id: Int!) {
chapter(id: $id) {
sections {
id
number
title
}
}
}
`,
props
)
const sections = useResult(result, [], data => data.chapter.sections)
return {
loading,
error,
sections,
noSections: computed(() => sections.value.length === 1)
}
}
}
</script>