mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-18 17:35:57 +00:00
docs: update count example (#743)
This commit is contained in:
parent
3bf6bb10fd
commit
d09a5531f2
@ -24,18 +24,21 @@ Under the hood, `defer: false` uses `<Suspense>` to block the loading of the rou
|
|||||||
|
|
||||||
### Example
|
### Example
|
||||||
|
|
||||||
```js [server/api/index.ts]
|
```js [server/api/count.ts]
|
||||||
let counter = 0
|
let counter = 0
|
||||||
export default () => ++counter
|
export default () => {
|
||||||
|
counter++
|
||||||
|
return JSON.stringify(counter)
|
||||||
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
```vue [pages/index.vue]
|
```vue [pages/index.vue]
|
||||||
<script setup>
|
<script setup>
|
||||||
const { data } = await useAsyncData('time', () => $fetch('/api/count'))
|
const { data } = await useAsyncData('count', () => $fetch('/api/count'))
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
Page visits: {{ data.count }}
|
Page visits: {{ data }}
|
||||||
</template>
|
</template>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user