2021-09-30 18:19:55 +00:00
|
|
|
<script setup>
|
2022-03-28 17:12:41 +00:00
|
|
|
const showMountain = ref(false)
|
|
|
|
|
|
|
|
const refreshing = ref(false)
|
|
|
|
const refreshAll = async () => {
|
|
|
|
refreshing.value = true
|
|
|
|
try {
|
|
|
|
await refreshNuxtData()
|
|
|
|
} finally {
|
|
|
|
refreshing.value = false
|
|
|
|
}
|
|
|
|
}
|
2021-04-23 20:30:43 +00:00
|
|
|
</script>
|
2021-12-23 19:27:08 +00:00
|
|
|
|
|
|
|
<template>
|
2022-01-17 10:05:24 +00:00
|
|
|
<NuxtExampleLayout example="use-async-data" show-tips>
|
2021-12-23 19:27:08 +00:00
|
|
|
<div>
|
2022-03-28 17:12:41 +00:00
|
|
|
<div class="flex justify-center gap-2">
|
|
|
|
<NButton @click="showMountain = !showMountain">
|
|
|
|
{{ showMountain ? 'Hide' : 'Show' }} Mountain
|
|
|
|
</NButton>
|
|
|
|
<NButton :disabled="refreshing" @click="refreshAll">
|
|
|
|
Refetch All Data
|
|
|
|
</NButton>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="flex justify-center gap-2">
|
|
|
|
<CounterExample />
|
|
|
|
</div>
|
|
|
|
<div class="flex justify-center gap-2">
|
|
|
|
<MountainExample v-if="showMountain" />
|
|
|
|
</div>
|
2021-12-23 19:27:08 +00:00
|
|
|
</div>
|
|
|
|
<template #tips>
|
|
|
|
<div>
|
2022-03-23 08:44:36 +00:00
|
|
|
<p>
|
|
|
|
This example shows how to use <code>useAsyncData</code> to fetch data from an API endpoint.
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
Nuxt will automatically read files in the
|
|
|
|
<a href="https://v3.nuxtjs.org/docs/directory-structure/server#api-routes" target="_blank">
|
|
|
|
<code>~/server/api</code> directory
|
|
|
|
</a>
|
|
|
|
to create API endpoints. Learn more about
|
|
|
|
<a href="https://v3.nuxtjs.org/docs/usage/data-fetching" target="_blank">data fetching</a>
|
|
|
|
</p>
|
2021-12-23 19:27:08 +00:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</NuxtExampleLayout>
|
|
|
|
</template>
|