2019-02-14 15:56:58 +00:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
{{ data }}
|
|
|
|
<button @click="update">
|
|
|
|
Fetch
|
|
|
|
</button>
|
|
|
|
<button @click="reload">
|
|
|
|
Reload
|
|
|
|
</button>
|
2020-12-17 11:49:59 +00:00
|
|
|
<code>{{ fetched }}</code>
|
2019-02-14 15:56:58 +00:00
|
|
|
</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 {
|
2020-12-17 11:49:59 +00:00
|
|
|
async asyncData ({ $config }) {
|
|
|
|
if ($config.generated) { return }
|
|
|
|
|
2019-02-14 15:56:58 +00:00
|
|
|
const data = await getData()
|
|
|
|
return { data }
|
|
|
|
},
|
2020-12-17 11:49:59 +00:00
|
|
|
data: () => ({
|
|
|
|
num: 10,
|
|
|
|
fetched: false
|
|
|
|
}),
|
|
|
|
async fetch () {
|
|
|
|
await new Promise((resolve) => {
|
|
|
|
this.fetched = true
|
|
|
|
resolve()
|
|
|
|
})
|
|
|
|
},
|
|
|
|
fetchKey (getCounter) {
|
|
|
|
return 'custom' + this.num + getCounter('custom')
|
|
|
|
},
|
2019-02-14 15:56:58 +00:00
|
|
|
methods: {
|
2019-07-10 10:45:49 +00:00
|
|
|
async update () {
|
2019-02-14 15:56:58 +00:00
|
|
|
this.data = await getData()
|
|
|
|
},
|
2019-07-10 10:45:49 +00:00
|
|
|
reload () {
|
2019-02-14 15:56:58 +00:00
|
|
|
window.location.reload()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|