forked from nuxt/nuxt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathusers.vue
More file actions
87 lines (84 loc) · 1.79 KB
/
users.vue
File metadata and controls
87 lines (84 loc) · 1.79 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<template>
<div class="container">
<NuxtLink v-if="page > 1" :to="'?page=' + (page - 1)">
< Prev
</NuxtLink>
<a v-else class="disabled">
< Prev
</a>
<span>{{ page }}/{{ totalPages }}</span>
<NuxtLink v-if="page < totalPages" :to="'?page=' + (page + 1)">
Next >
</NuxtLink>
<a v-else class="disabled">
Next >
</a>
<ul>
<li v-for="user in users" :key="user.id">
<img :src="user.avatar" class="avatar">
<span>{{ user.first_name }} {{ user.last_name }}</span>
</li>
</ul>
<p>
<NuxtLink to="/">
Back home
</NuxtLink>
</p>
</div>
</template>
<script>
export default {
// Watch for $route.query.page to call Component methods (asyncData, fetch, validate, layout, etc.)
watchQuery: ['page'],
// Key for <NuxtChild> (transitions)
key: to => to.fullPath,
// Called to know which transition to apply
transition (to, from) {
if (!from) { return 'slide-left' }
return +to.query.page < +from.query.page ? 'slide-right' : 'slide-left'
},
async asyncData ({ query, $axios }) {
const page = +query.page || 1
const data = await $axios.$get(`https://reqres.in/api/users?page=${page}`)
return {
page: +data.page,
totalPages: data.total_pages,
users: data.data
}
}
}
</script>
<style scoped>
a {
display: inline-block;
margin: 0 1em;
color: #34495e;
text-decoration: none;
}
a.disabled {
color: #ccc;
}
ul {
margin: auto;
padding: 0;
width: 100%;
max-width: 400px;
padding-top: 40px;
}
li {
list-style-type: none;
width: 400px;
border: 1px #ddd solid;
overflow: hidden;
}
li img {
float: left;
width: 100px;
height: 100px;
}
li span {
display: inline-block;
padding-top: 40px;
text-transform: uppercase;
}
</style>