-
Notifications
You must be signed in to change notification settings - Fork 1
/
jokes.vue
48 lines (42 loc) · 1.11 KB
/
jokes.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
<template>
<div class="flex-1">
<mb-button :to="{ name: 'index' }">
<mb-icon icon="chevron-left" type="solid" /> Back to home
</mb-button>
<div class="jokes flex flex-col items-center">
<mb-heading accent>Jokes</mb-heading>
<mb-button @click="fetchJokes">Fetch jokes</mb-button>
<div v-show="!jokes.length" class="my-4">Loading jokes...</div>
<div v-show="jokes.length">
<mb-box v-for="joke in jokes" :key="joke.id" class="m-6">
<mb-heading :level="2">{{ joke.setup }}</mb-heading>
<mb-heading :level="3">{{ joke.punchline }}</mb-heading>
</mb-box>
</div>
</div>
</div>
</template>
<script>
import MbHeading from '~/components/global/MbHeading.vue'
export default {
components: { MbHeading },
data({ $axios }) {
return {
jokes: [],
}
},
created() {
this.fetchJokes()
},
methods: {
async fetchJokes() {
this.jokes = []
const { data } = await this.$axios.get(
'https://official-joke-api.appspot.com/random_ten'
)
this.jokes = data
},
},
}
</script>
<style></style>