Nuxt 提供了可组合函数和实用工具,用于一流的服务器端渲染支持。
setResponseStatus 用于设置响应的 statusCode(和可选的 statusMessage)。
setResponseStatus 只能在 Nuxt 上下文中调用。const event = useRequestEvent()
// event will be undefined in the browser
if (event) {
// Set the status code to 404 for a custom 404 page
setResponseStatus(event, 404)
// Set the status message as well
setResponseStatus(event, 404, 'Page Not Found')
}
setResponseStatus 将不起作用。