mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-13 09:33:54 +00:00
1.3 KiB
1.3 KiB
title | description | links | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
useResponseHeader | Use useResponseHeader to set a server response header. |
|
You can use the built-in useResponseHeader
composable to set any server response header within your pages, components, and plugins.
// Set the a custom response header
useResponseHeader('X-My-Header', 'my-value');
::tip
As it is not retreiving a value, useResponseHeader
never returns anything.
::
Example
We can use useResponseHeader
to easily set a response header on a per-page basis.
<script setup>
// pages/test.vue
useResponseHeader('X-My-Header', '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 to set a response header for all pages.
export default defineNuxtRouteMiddleware((to, from) => {
useResponseHeader('X-My-Header', 'my-value');
});