docs: use updated h3 utils (#6818)

This commit is contained in:
Qin Guan 2022-08-22 16:49:27 +08:00 committed by GitHub
parent d3ccb79920
commit ae39a821b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -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 }
}) })
``` ```

View File

@ -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)