feat: 위키 저장소 초기 커밋
- CLAUDE.md 운영 규칙 - wiki/ 정리된 지식 페이지 (Nuxt + Claude Code) - raw/ 원본 자료 - reference/ Nuxt 4.x 공식 문서 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
47
reference/4.api/2.composables/use-response-header.md
Normal file
47
reference/4.api/2.composables/use-response-header.md
Normal file
@@ -0,0 +1,47 @@
|
||||
---
|
||||
title: "useResponseHeader"
|
||||
description: "Use useResponseHeader to set a server response header."
|
||||
links:
|
||||
- label: Source
|
||||
icon: i-simple-icons-github
|
||||
to: https://github.com/nuxt/nuxt/blob/main/packages/nuxt/src/app/composables/ssr.ts
|
||||
size: xs
|
||||
---
|
||||
|
||||
::important
|
||||
This composable is available in Nuxt v3.14+.
|
||||
::
|
||||
|
||||
You can use the built-in [`useResponseHeader`](/docs/4.x/api/composables/use-response-header) composable to set any server response header within your pages, components, and plugins.
|
||||
|
||||
```ts
|
||||
// Set a custom response header
|
||||
const header = useResponseHeader('X-My-Header')
|
||||
header.value = 'my-value'
|
||||
```
|
||||
|
||||
## Example
|
||||
|
||||
We can use `useResponseHeader` to easily set a response header on a per-page basis.
|
||||
|
||||
```vue [app/pages/test.vue]
|
||||
<script setup>
|
||||
// pages/test.vue
|
||||
const header = useResponseHeader('X-My-Header')
|
||||
header.value = 'my-value'
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<h1>Test page with custom header</h1>
|
||||
<p>The response from the server for this "/test" page will have a custom "X-My-Header" header.</p>
|
||||
</template>
|
||||
```
|
||||
|
||||
We can use `useResponseHeader` for example in Nuxt [middleware](/docs/4.x/directory-structure/app/middleware) to set a response header for all pages.
|
||||
|
||||
```ts [app/middleware/my-header-middleware.ts]
|
||||
export default defineNuxtRouteMiddleware((to, from) => {
|
||||
const header = useResponseHeader('X-My-Always-Header')
|
||||
header.value = `I'm Always here!`
|
||||
})
|
||||
```
|
||||
Reference in New Issue
Block a user