mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-16 21:58:19 +00:00
docs: update cookie example with defineEventHandler
(#5405)
This commit is contained in:
parent
63b0457a69
commit
1449e70541
@ -143,18 +143,16 @@ You can use `useCookie` and `setCookie` from [`h3`](https://github.com/unjs/h3)
|
||||
**Example:**
|
||||
|
||||
```js
|
||||
import { useCookie, setCookie } from 'h3'
|
||||
|
||||
export default (req, res) => {
|
||||
export default defineEventHandler(event => {
|
||||
// Read counter cookie
|
||||
let counter = useCookie(req, 'counter') || 0
|
||||
let counter = useCookie(event, 'counter') || 0
|
||||
|
||||
// Increase counter cookie by 1
|
||||
setCookie(res, 'counter', ++counter)
|
||||
setCookie(event, 'counter', ++counter)
|
||||
|
||||
// Send JSON response
|
||||
return { counter }
|
||||
}
|
||||
})
|
||||
```
|
||||
|
||||
:LinkExample{link="/examples/composables/use-cookie"}
|
||||
|
Loading…
Reference in New Issue
Block a user