Svelte基础
Svelte高阶
上下文API
特殊元素
接下来
SvelteKit基础
Shared modules
API routes
$app/state
Errors and redirects
Advanced SvelteKit
Page options
Link options
Advanced routing
Advanced loading
Environment variables
Conclusion
有时候,有时候,需要设置下头信息呀有没有?! 比如设置下缓存时间,返回内容类型啊有没有?!
在load
函数还有后面会遇到的form actions, hooks和API routes里可以使用setHeaders
:
Inside a
load
function (as well as in form actions, hooks and API routes, which we’ll learn about later) you have access to asetHeaders
function, which — unsurprisingly — can be used to set headers on the response. Most commonly, you’d use it to customise caching behaviour with theCache-Control
response header, but for the sake of this tutorial we’ll do something less advisable and more dramatic:
src/routes/+page.server
export function load({ setHeaders }) {
setHeaders({
'Content-Type': 'text/plain'
});
}
(可能需要刷新下Iframe才能看到效果)
(You may need to reload the iframe to see the effect.)
1
<h1>hello world</h1>