setResponseStatus

源文件
setResponseStatus 用于设置响应的状态码(以及可选的 statusText)。

Nuxt 提供了用于一流服务端渲染支持的组合式函数和工具库。

setResponseStatus 用于设置响应的状态码(以及可选的 statusText)。

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 > 入门 > 错误处理