mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-18 02:07:14 +00:00
2015140d12
* pkg(nuxt-start): add node-fetch, unfetch * pkg(vue-app): add node-fetch, unfetch * add yarn.lock * feat(config): _app.fetch options * feat(builder): add fetch to templateVars * feat(vue-app): polyfill global with fetch * feat(fixtures/basic): /api/test * add fetch example to fixtures * remove unfetch from nuxt-start * update template snapshot * revert extra new line in server.js * single line if
35 lines
617 B
Vue
35 lines
617 B
Vue
<template>
|
|
<div>
|
|
{{ data }}
|
|
<button @click="update">
|
|
Fetch
|
|
</button>
|
|
<button @click="reload">
|
|
Reload
|
|
</button>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
const name = process.server ? 'server' : 'client'
|
|
const baseURL = 'http://localhost:3000/api'
|
|
const getData = () => fetch(`${baseURL}/test`)
|
|
.then(r => r.text())
|
|
.then(r => r + ` (From ${name})`)
|
|
|
|
export default {
|
|
async asyncData() {
|
|
const data = await getData()
|
|
return { data }
|
|
},
|
|
methods: {
|
|
async update() {
|
|
this.data = await getData()
|
|
},
|
|
reload() {
|
|
window.location.reload()
|
|
}
|
|
}
|
|
}
|
|
</script>
|