2022-03-16 15:49:53 +00:00
|
|
|
import { defineComponent, ref, onErrorCaptured } from 'vue'
|
|
|
|
import { useNuxtApp } from '#app'
|
|
|
|
|
|
|
|
export default defineComponent({
|
2022-07-26 13:36:58 +00:00
|
|
|
emits: {
|
|
|
|
error (_error: unknown) {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
},
|
2022-03-16 15:49:53 +00:00
|
|
|
setup (_props, { slots, emit }) {
|
2022-08-12 17:47:58 +00:00
|
|
|
const error = ref<Error | null>(null)
|
2022-03-16 15:49:53 +00:00
|
|
|
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?.()
|
|
|
|
}
|
|
|
|
})
|