<template> <div> <template v-if="$fetchState.pending"> Loading ... </template> <template v-else-if="$fetchState.error"> Error: {{ $fetchState.error.message }} </template> <template v-else> OK </template> </div></template><script>export default { async fetch() { const id = this.$route.params.id if (!id) { this.error('Missing ID', 404) return } // load data }, methods: { error(message, statusCode) { if (process.server) { this.$nuxt.context.res.statusCode = statusCode } // this doesn't work well under certain condition // this.$nuxt.error({ message: 'Place not found', statusCode: 404 }) throw new Error(message) }, }}</script>
References: