mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-06 06:03:58 +00:00
34 lines
653 B
Vue
34 lines
653 B
Vue
<template>
|
|
<div class="user">
|
|
<h3>{{ name }}</h3>
|
|
<h4>@{{ username }}</h4>
|
|
<p>Email : {{ email }}</p>
|
|
<p><nuxt-link to="/">List of users</nuxt-link></p>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import axios from 'axios'
|
|
|
|
export default {
|
|
validate ({ params }) {
|
|
return !isNaN(+params.id)
|
|
},
|
|
data ({ params, error }) {
|
|
return axios.get(`https://jsonplaceholder.typicode.com/users/${+params.id}`)
|
|
.then((res) => res.data)
|
|
.catch(() => {
|
|
error({ message: 'User not found', statusCode: 404 })
|
|
})
|
|
}
|
|
}
|
|
</script>
|
|
|
|
<style scoped>
|
|
.user {
|
|
text-align: center;
|
|
margin-top: 100px;
|
|
font-family: sans-serif;
|
|
}
|
|
</style>
|