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 -->
<NuxtErrorBoundary @error="someErrorLogger">
<!-- You use the default slot to render your content -->
<template #error="{ error }">
You can display the error locally here.
<button @click="error = null">
<template #error="{ error, clearError }">
You can display the error locally here: {{ error }}
<button @click="clearError">
This will clear the error.
</button>
</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?.()
}
})