Fix example for v1

This commit is contained in:
Sébastien Chopin 2017-07-09 12:23:03 +02:00
parent b921191f91
commit a869637615
2 changed files with 9 additions and 12 deletions

View File

@ -2,6 +2,5 @@ module.exports = {
build: { build: {
vendor: ['axios'] vendor: ['axios']
}, },
css: ['~/assets/main.css'], css: ['~/assets/main.css']
loading: false
} }

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="container" :key="page"> <div class="container">
<nuxt-link v-if="page > 1" :to="'?page=' + (page - 1)">&lt; Prev</nuxt-link> <nuxt-link v-if="page > 1" :to="'?page=' + (page - 1)">&lt; Prev</nuxt-link>
<a v-else class="disabled">&lt; Prev</a> <a v-else class="disabled">&lt; Prev</a>
<span>{{ page }}/{{ totalPages }}</span> <span>{{ page }}/{{ totalPages }}</span>
@ -23,16 +23,14 @@ export default {
if (!from) return 'slide-left' if (!from) return 'slide-left'
return +to.query.page < +from.query.page ? 'slide-right' : 'slide-left' return +to.query.page < +from.query.page ? 'slide-right' : 'slide-left'
}, },
asyncData ({ query }) { async asyncData ({ query }) {
const page = +query.page || 1 const page = +query.page || 1
return axios.get(`https://reqres.in/api/users?page=${page}`) const { data } = await axios.get(`https://reqres.in/api/users?page=${page}`)
.then((res) => {
return { return {
page: +res.data.page, page: +data.page,
totalPages: res.data.total_pages, totalPages: data.total_pages,
users: res.data.data users: data.data
} }
})
} }
} }
</script> </script>