feat(nuxt): add scoped helper for clearing error within boundary (#20508)

This commit is contained in:
Daniel Roe 2023-04-29 23:32:29 +01:00 committed by GitHub
parent 1444d89e3b
commit e1e3d2cd8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 4 deletions

View File

@ -156,9 +156,9 @@ If you navigate to another route, the error will be cleared automatically.
<!-- some content --> <!-- some content -->
<NuxtErrorBoundary @error="someErrorLogger"> <NuxtErrorBoundary @error="someErrorLogger">
<!-- You use the default slot to render your content --> <!-- You use the default slot to render your content -->
<template #error="{ error }"> <template #error="{ error, clearError }">
You can display the error locally here. You can display the error locally here: {{ error }}
<button @click="error = null"> <button @click="clearError">
This will clear the error. This will clear the error.
</button> </button>
</template> </template>

View File

@ -19,6 +19,10 @@ export default defineComponent({
} }
}) })
return () => error.value ? slots.error?.({ error }) : slots.default?.() function clearError () {
error.value = null
}
return () => error.value ? slots.error?.({ error, clearError }) : slots.default?.()
} }
}) })