2016-11-07 20:38:51 +00:00
|
|
|
<template>
|
2016-12-19 19:35:34 +00:00
|
|
|
<div class="user">
|
|
|
|
<h3>{{ name }}</h3>
|
|
|
|
<h4>@{{ username }}</h4>
|
|
|
|
<p>Email : {{ email }}</p>
|
|
|
|
<p><nuxt-link to="/">List of users</nuxt-link></p>
|
2016-11-07 20:38:51 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import axios from 'axios'
|
|
|
|
|
|
|
|
export default {
|
2017-10-31 13:43:55 +00:00
|
|
|
validate({ params }) {
|
2016-12-19 19:35:34 +00:00
|
|
|
return !isNaN(+params.id)
|
2016-12-16 16:46:30 +00:00
|
|
|
},
|
2017-10-31 13:43:55 +00:00
|
|
|
async asyncData({ params, error }) {
|
2017-07-08 16:52:29 +00:00
|
|
|
try {
|
|
|
|
const { data } = await axios.get(`https://jsonplaceholder.typicode.com/users/${+params.id}`)
|
|
|
|
return data
|
|
|
|
} catch (e) {
|
2016-11-17 10:57:02 +00:00
|
|
|
error({ message: 'User not found', statusCode: 404 })
|
2017-07-08 16:52:29 +00:00
|
|
|
}
|
2016-11-07 20:38:51 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2016-11-07 20:58:56 +00:00
|
|
|
<style scoped>
|
2016-12-19 19:35:34 +00:00
|
|
|
.user {
|
2016-12-11 15:40:18 +00:00
|
|
|
text-align: center;
|
2016-12-19 19:35:34 +00:00
|
|
|
margin-top: 100px;
|
|
|
|
font-family: sans-serif;
|
2016-12-11 15:40:18 +00:00
|
|
|
}
|
2016-11-07 20:38:51 +00:00
|
|
|
</style>
|