docs: update count example (#743)

This commit is contained in:
Clément Ollivier 2021-10-12 12:21:00 +02:00 committed by GitHub
parent 3bf6bb10fd
commit d09a5531f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 4 deletions

View File

@ -24,18 +24,21 @@ Under the hood, `defer: false` uses `<Suspense>` to block the loading of the rou
### Example
```js [server/api/index.ts]
```js [server/api/count.ts]
let counter = 0
export default () => ++counter
export default () => {
counter++
return JSON.stringify(counter)
}
```
```vue [pages/index.vue]
<script setup>
const { data } = await useAsyncData('time', () => $fetch('/api/count'))
const { data } = await useAsyncData('count', () => $fetch('/api/count'))
</script>
<template>
Page visits: {{ data.count }}
Page visits: {{ data }}
</template>
```