透過 100+ 個技巧的集合來學習 Nuxt!

setResponseStatus

setResponseStatus 設定回應的 statusCode(以及可選的 statusMessage)。

Nuxt 提供了 composables 和工具程式,以提供一流的伺服器端渲染支援。

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 將不會有任何效果。
請在 文件 > 開始使用 > 錯誤處理 中閱讀更多資訊。