Nuxt/playground/pages/composables/asyncData/series.vue
Daniel Roe efabacd8e2
feat(app): asyncData with global state and explicit key (#37)
Co-authored-by: Pooya Parsa <pyapar@gmail.com>
Co-authored-by: Sébastien Chopin <seb@nuxtjs.com>
2021-04-03 12:03:20 +02:00

40 lines
832 B
Vue

<template>
<div>
<nuxt-link to="/">
Home
</nuxt-link>
<h2>{{ $route.path }}</h2>
<pre>{{ foo }}</pre>
<pre>{{ bar }}</pre>
<pre>{{ from }}</pre>
</div>
</template>
<script>
import { useAsyncData } from 'nuxt/app/composables'
const waitFor = (ms = 0) => new Promise(resolve => setTimeout(resolve, ms))
export default {
async setup () {
const asyncData = useAsyncData()
const { data: foo } = await asyncData('foo', async () => {
await waitFor(500)
return { foo: true }
})
const { data: bar } = await asyncData('bar', async () => {
await waitFor(500)
return { bar: true }
})
const { data: from } = await asyncData('from', () => ({ from: process.server ? 'server' : 'client' }))
return {
foo,
bar,
from
}
}
}
</script>