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

30 lines
573 B
Vue

<template>
<div>
<nuxt-link to="/fetch-conditional?fetch_client=true">
Fetch on client
</nuxt-link>
<p v-if="$fetchState.pending">
Fetching...
</p>
<pre v-else>{{ team }}</pre>
</div>
</template>
<script>
export default {
data () {
return {
team: []
}
},
async fetch () {
const url = (process.server ? `http://${this.$ssrContext.req.headers.host}` : '')
this.team = await fetch(`${url}/team.json`).then(res => res.json())
},
fetchOnServer () {
return !this.$route.query.fetch_client
}
}
</script>