mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-16 02:44:51 +00:00
12304909bc
* feat(nuxt3): add `<NuxtErrorBoundary>` component for fine-grained error handling * feat: add `@error` event handling * fix: don't clear error on nav * fix: remove `clearError` wrapper * fix: remove outdated implementation * update clear error * upddate example with FaultyComponent Co-authored-by: Pooya Parsa <pyapar@gmail.com>
51 lines
1.2 KiB
Vue
51 lines
1.2 KiB
Vue
<script setup lang="ts">
|
|
import { throwError } from '#app'
|
|
const route = useRoute()
|
|
if ('setup' in route.query) {
|
|
throw new Error('error in setup')
|
|
}
|
|
if ('mounted' in route.query) {
|
|
onMounted(() => {
|
|
throw new Error('error in mounted')
|
|
})
|
|
}
|
|
function triggerError () {
|
|
throw new Error('manually triggered error')
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<NuxtExampleLayout example="with-errors">
|
|
<template #nav>
|
|
<nav class="flex align-center gap-4 p-4">
|
|
<NuxtLink to="/" class="n-link-base">
|
|
Home
|
|
</NuxtLink>
|
|
<NuxtLink to="/other" class="n-link-base">
|
|
Other
|
|
</NuxtLink>
|
|
<NuxtLink to="/404" class="n-link-base">
|
|
404
|
|
</NuxtLink>
|
|
<NuxtLink to="/?middleware" class="n-link-base">
|
|
Middleware
|
|
</NuxtLink>
|
|
<button class="n-link-base" @click="throwError">
|
|
Trigger fatal error
|
|
</button>
|
|
<button class="n-link-base" @click="triggerError">
|
|
Trigger non-fatal error
|
|
</button>
|
|
</nav>
|
|
</template>
|
|
|
|
<FaultyComponent />
|
|
|
|
<template #footer>
|
|
<div class="text-center p-4 op-50">
|
|
Current route: <code>{{ route.path }}</code>
|
|
</div>
|
|
</template>
|
|
</NuxtExampleLayout>
|
|
</template>
|