mirror of
https://github.com/nuxt/nuxt.git
synced 2025-02-19 23:21:09 +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:**
|
**Example:**
|
||||||
|
|
||||||
```js
|
```js
|
||||||
import { useCookie, setCookie } from 'h3'
|
export default defineEventHandler(event => {
|
||||||
|
|
||||||
export default (req, res) => {
|
|
||||||
// Read counter cookie
|
// Read counter cookie
|
||||||
let counter = useCookie(req, 'counter') || 0
|
let counter = useCookie(event, 'counter') || 0
|
||||||
|
|
||||||
// Increase counter cookie by 1
|
// Increase counter cookie by 1
|
||||||
setCookie(res, 'counter', ++counter)
|
setCookie(event, 'counter', ++counter)
|
||||||
|
|
||||||
// Send JSON response
|
// Send JSON response
|
||||||
return { counter }
|
return { counter }
|
||||||
}
|
})
|
||||||
```
|
```
|
||||||
|
|
||||||
:LinkExample{link="/examples/composables/use-cookie"}
|
:LinkExample{link="/examples/composables/use-cookie"}
|
||||||
|
Loading…
Reference in New Issue
Block a user