mirror of
https://github.com/nuxt/nuxt.git
synced 2024-12-12 15:27:13 +00:00
92018e586b
[release]
51 lines
951 B
Vue
51 lines
951 B
Vue
<template>
|
|
<div>
|
|
{{ data }}
|
|
<button @click="update">
|
|
Fetch
|
|
</button>
|
|
<button @click="reload">
|
|
Reload
|
|
</button>
|
|
<code>{{ fetched }}</code>
|
|
</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 ({ $config }) {
|
|
if ($config.generated) { return }
|
|
|
|
const data = await getData()
|
|
return { data }
|
|
},
|
|
data: () => ({
|
|
num: 10,
|
|
fetched: false
|
|
}),
|
|
async fetch () {
|
|
await new Promise((resolve) => {
|
|
this.fetched = true
|
|
resolve()
|
|
})
|
|
},
|
|
fetchKey (getCounter) {
|
|
return 'custom' + this.num + getCounter('custom')
|
|
},
|
|
methods: {
|
|
async update () {
|
|
this.data = await getData()
|
|
},
|
|
reload () {
|
|
window.location.reload()
|
|
}
|
|
}
|
|
}
|
|
</script>
|