Nuxt/test/fixtures/fetch/pages/fetch-button.vue

27 lines
464 B
Vue

<template>
<div>
<p v-if="$fetchState.pending">
Fetching...
</p>
<pre v-else>{{ team }}</pre>
<button @click="$fetch">
Refresh
</button>
</div>
</template>
<script>
export default {
async fetch () {
const url = (process.server ? `http://${this.$ssrContext.req.headers.host}` : '')
this.team = await fetch(`${url}/team.json`).then(res => res.json())
},
data () {
return {
team: []
}
}
}
</script>