mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-24 06:35:10 +00:00
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>
|