setResponseStatus

源文件
setResponseStatus 设置响应的状态码(可选地还可设置状态消息)。

Nuxt 提供可组合函数和实用工具,用于一流的服务器端渲染支持。

setResponseStatus 设置响应的状态码(可选地还可设置状态消息)。

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 不会产生任何效果。
阅读更多内容请参见 文档 > 4 X > 入门 > 错误处理