Nuxt Nation カンファレンスが開催されます。11月12日~13日にご参加ください。

setResponseStatus

setResponseStatus は、レスポンスのステータスコード (およびオプションで statusMessage) を設定します。

Nuxt は、ファーストクラスのサーバーサイドレンダリングをサポートするためのコンポーザブルとユーティリティを提供します。

setResponseStatus は、レスポンスのステータスコード (およびオプションで 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 は効果がありません。
ドキュメント > はじめに > エラー処理 で詳細をご覧ください。