2019-02-14 15:56:58 +00:00
|
|
|
<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 {
|
2019-07-10 10:45:49 +00:00
|
|
|
async asyncData () {
|
2019-02-14 15:56:58 +00:00
|
|
|
const data = await getData()
|
|
|
|
return { data }
|
|
|
|
},
|
|
|
|
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>
|