setResponseStatus

setResponseStatus 设置响应的 statusCode(以及可选的 statusMessage)。

Nuxt 提供了可组合项和实用程序,以实现一流的服务器端渲染支持。

¥Nuxt provides composables and utilities for first-class server-side-rendering support.

setResponseStatus 设置响应的 statusCode(以及可选的 statusMessage)。

¥setResponseStatus sets the statusCode (and optionally the statusMessage) of the response.

setResponseStatus 只能在 Nuxt context 中调用。
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 将不起作用。
Read more in Docs > Getting Started > Error Handling.