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
將不會有任何作用。