mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
docs: use updated h3 utils (#6818)
This commit is contained in:
parent
d3ccb79920
commit
ae39a821b5
@ -155,7 +155,7 @@ export default defineEventHandler((event) => {
|
|||||||
|
|
||||||
```ts
|
```ts
|
||||||
export default defineEventHandler((event) => {
|
export default defineEventHandler((event) => {
|
||||||
const cookies = useCookies(event)
|
const cookies = parseCookies(event)
|
||||||
return { cookies }
|
return { cookies }
|
||||||
})
|
})
|
||||||
```
|
```
|
||||||
|
@ -138,14 +138,14 @@ Specifies a function that returns the cookie's default value. The function can a
|
|||||||
|
|
||||||
## Handling Cookies in API Routes
|
## Handling Cookies in API Routes
|
||||||
|
|
||||||
You can use `useCookie` and `setCookie` from [`h3`](https://github.com/unjs/h3) package to set cookies in server API routes.
|
You can use `getCookie` and `setCookie` from [`h3`](https://github.com/unjs/h3) package to set cookies in server API routes.
|
||||||
|
|
||||||
**Example:**
|
**Example:**
|
||||||
|
|
||||||
```js
|
```js
|
||||||
export default defineEventHandler(event => {
|
export default defineEventHandler(event => {
|
||||||
// Read counter cookie
|
// Read counter cookie
|
||||||
let counter = useCookie(event, 'counter') || 0
|
let counter = getCookie(event, 'counter') || 0
|
||||||
|
|
||||||
// Increase counter cookie by 1
|
// Increase counter cookie by 1
|
||||||
setCookie(event, 'counter', ++counter)
|
setCookie(event, 'counter', ++counter)
|
||||||
|
Loading…
Reference in New Issue
Block a user