2017-09-08 10:42:00 +00:00
|
|
|
<template>
|
|
|
|
<div class="container">
|
2018-11-24 18:49:19 +00:00
|
|
|
<NuxtLink v-if="page > 1" :to="'?page=' + (page - 1)">
|
|
|
|
< Prev
|
|
|
|
</NuxtLink>
|
|
|
|
<a v-else class="disabled">
|
|
|
|
< Prev
|
|
|
|
</a>
|
2017-09-08 10:42:00 +00:00
|
|
|
<span>{{ page }}/{{ totalPages }}</span>
|
2018-11-24 18:49:19 +00:00
|
|
|
<NuxtLink v-if="page < totalPages" :to="'?page=' + (page + 1)">
|
|
|
|
Next >
|
|
|
|
</NuxtLink>
|
|
|
|
<a v-else class="disabled">
|
|
|
|
Next >
|
|
|
|
</a>
|
2017-09-08 10:42:00 +00:00
|
|
|
<ul>
|
2017-11-06 17:24:43 +00:00
|
|
|
<li v-for="user in users" :key="user.id">
|
2018-08-31 20:34:12 +00:00
|
|
|
<img :src="user.avatar" class="avatar">
|
2017-09-08 10:42:00 +00:00
|
|
|
<span>{{ user.first_name }} {{ user.last_name }}</span>
|
|
|
|
</li>
|
|
|
|
</ul>
|
2018-11-24 18:49:19 +00:00
|
|
|
<p>
|
|
|
|
<NuxtLink to="/">
|
|
|
|
Back home
|
|
|
|
</NuxtLink>
|
|
|
|
</p>
|
2017-09-08 10:42:00 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import axios from 'axios'
|
|
|
|
|
|
|
|
export default {
|
2017-11-06 17:24:43 +00:00
|
|
|
// Watch for $route.query.page to call Component methods (asyncData, fetch, validate, layout, etc.)
|
|
|
|
watchQuery: ['page'],
|
2018-11-24 18:49:19 +00:00
|
|
|
// Key for <NuxtChild> (transitions)
|
2018-08-06 00:12:44 +00:00
|
|
|
key: to => to.fullPath,
|
2017-11-06 17:24:43 +00:00
|
|
|
// Called to know which transition to apply
|
2017-10-31 13:43:55 +00:00
|
|
|
transition(to, from) {
|
2017-09-08 10:42:00 +00:00
|
|
|
if (!from) return 'slide-left'
|
|
|
|
return +to.query.page < +from.query.page ? 'slide-right' : 'slide-left'
|
|
|
|
},
|
2017-10-31 13:43:55 +00:00
|
|
|
async asyncData({ query }) {
|
2017-11-06 17:24:43 +00:00
|
|
|
const page = +(query.page || 1)
|
2017-09-08 10:42:00 +00:00
|
|
|
const { data } = await axios.get(`https://reqres.in/api/users?page=${page}`)
|
|
|
|
return {
|
2017-11-06 17:24:43 +00:00
|
|
|
page,
|
2017-09-08 10:42:00 +00:00
|
|
|
totalPages: data.total_pages,
|
|
|
|
users: data.data
|
|
|
|
}
|
2018-01-17 08:38:11 +00:00
|
|
|
},
|
|
|
|
head: {
|
|
|
|
title: 'Users'
|
2017-09-08 10:42:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</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>
|