<NuxtErrorBoundary>

Source
The <NuxtErrorBoundary> component handles client-side errors happening in its default slot.
The <NuxtErrorBoundary> uses Vue's onErrorCaptured hook under the hood.

Events

  • @error: Event emitted when the default slot of the component throws an error.
<template>
  <NuxtErrorBoundary @error="logSomeError">
    <!-- ... -->
  </NuxtErrorBoundary>
</template>

Slots

  • #error: Specify a fallback content to display in case of error.
<template>
  <NuxtErrorBoundary>
    <!-- ... -->
    <template #error="{ error, clearError }">
      <p>An error occurred: {{ error }}</p>

      <button @click="clearError">
        Clear error
      </button>
    </template>
  </NuxtErrorBoundary>
</template>
Read more in Docs > 4 X > Getting Started > Error Handling.

Examples

Accessing error and clearError in script

You can access error and clearError properties within the component's script as below:

<template>
  <NuxtErrorBoundary ref="errorBoundary">
    <!-- ... -->
  </NuxtErrorBoundary>
</template>

<script setup lang="ts">
const errorBoundary = useTemplateRef('errorBoundary')

// errorBoundary.value?.error
// errorBoundary.value?.clearError()
</script>