Nuxt/examples/new-fetch/components/Author.vue
renovate[bot] e934da3c36
chore(deps): update devdependency @nuxtjs/eslint-config to v5 (#8345)
Co-authored-by: Renovate Bot <bot@renovateapp.com>
Co-authored-by: Clark Du <clark.duxin@gmail.com>
2020-11-14 17:10:53 +00:00

31 lines
535 B
Vue

<template>
<p v-if="$fetchState.error">
Could not fetch Author
</p>
<p v-else>
Written by {{ $fetchState.pending ? '...' : user.name }} <button @click="$fetch">
Refresh
</button>
</p>
</template>
<script>
export default {
props: {
userId: {
type: Number,
required: true
}
},
data () {
return {
user: {}
}
},
async fetch () {
this.user = await this.$http.$get(`https://jsonplaceholder.typicode.com/users/${this.userId}`)
},
fetchOnServer: false
}
</script>