Nuxt/packages/nuxt/src/app/components/nuxt-error-boundary.ts
Anthony Fu f350a70775
refactor(nuxt): enable strict type checking (#6368)
Co-authored-by: Pooya Parsa <pooya@pi0.io>
2022-08-12 19:47:58 +02:00

25 lines
566 B
TypeScript

import { defineComponent, ref, onErrorCaptured } from 'vue'
import { useNuxtApp } from '#app'
export default defineComponent({
emits: {
error (_error: unknown) {
return true
}
},
setup (_props, { slots, emit }) {
const error = ref<Error | null>(null)
const nuxtApp = useNuxtApp()
onErrorCaptured((err) => {
if (process.client && !nuxtApp.isHydrating) {
emit('error', err)
error.value = err
return false
}
})
return () => error.value ? slots.error?.({ error }) : slots.default?.()
}
})