mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 16:12:12 +00:00
b11e9c0e51
- [ ] babel-eslint https://github.com/babel/babel-eslint/issues/664 - [x] eslint-config-standard-jsx https://github.com/standard/eslint-config-standard-jsx/issues/32 - [x] eslint-config-standard to be stable release https://github.com/standard/eslint-config-standard/issues/123 - [x] eslint-plugin-html - [x] eslint-plugin-import - [x] eslint-plugin-jest - [x] eslint-plugin-node - [x] eslint-plugin-promise - [x] eslint-plugin-standard https://github.com/standard/eslint-plugin-standard/issues/29 - [x] eslint-plugin-vue https://github.com/vuejs/eslint-plugin-vue/pull/504 - [x] eslint-plugin-react https://github.com/yannickcr/eslint-plugin-react/releases/tag/v7.10.0
80 lines
1.8 KiB
Vue
80 lines
1.8 KiB
Vue
<template>
|
|
<div class="container">
|
|
<nuxt-link v-if="page > 1" :to="'?page=' + (page - 1)">< Prev</nuxt-link>
|
|
<a v-else class="disabled">< Prev</a>
|
|
<span>{{ page }}/{{ totalPages }}</span>
|
|
<nuxt-link v-if="page < totalPages" :to="'?page=' + (page + 1)">Next ></nuxt-link>
|
|
<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><nuxt-link to="/">Back home</nuxt-link></p>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import axios from 'axios'
|
|
|
|
export default {
|
|
// Watch for $route.query.page to call Component methods (asyncData, fetch, validate, layout, etc.)
|
|
watchQuery: ['page'],
|
|
// Key for <nuxt-child> (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 }) {
|
|
const page = +(query.page || 1)
|
|
const { data } = await axios.get(`https://reqres.in/api/users?page=${page}`)
|
|
return {
|
|
page,
|
|
totalPages: data.total_pages,
|
|
users: data.data
|
|
}
|
|
},
|
|
head: {
|
|
title: 'Users'
|
|
}
|
|
}
|
|
</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>
|