onErrorCaptured in Vue?onErrorCaptured is a Vue Composition API hook that catches errors from child components during rendering, lifecycle hooks, or watchers. It acts like an error boundary to prevent the whole app from crashing.
onErrorCaptured in a Vue component?Inside the setup() function, call onErrorCaptured((error, instance, info) => { ... }). Return true to stop the error from propagating further, or false or nothing to continue passing it up.
onErrorCaptured callback receive?- error: The actual error object thrown.
- instance: The Vue component instance where the error happened.
- info: A string describing the lifecycle hook or event during which the error occurred.
onErrorCaptured returns true?Returning true tells Vue that the error was handled and stops the error from propagating to parent components or the global error handler.
onErrorCaptured catch errors from asynchronous code like setTimeout?No, onErrorCaptured only catches errors during rendering and lifecycle hooks. Errors in asynchronous callbacks like setTimeout need to be handled separately.
onErrorCaptured in a Vue component?onErrorCaptured is a Composition API hook and must be called inside setup().
true from onErrorCaptured do?Returning true signals Vue that the error was handled and prevents it from propagating further.
onErrorCaptured catch?onErrorCaptured catches errors during rendering and lifecycle hooks, not asynchronous or syntax errors.
onErrorCaptured callback receive?The callback receives the error object, the component instance, and a string describing where the error happened.
onErrorCaptured returns false or nothing, what happens?Returning false or nothing lets the error continue to propagate up the component tree.
onErrorCaptured works as an error boundary in Vue components.onErrorCaptured and how you handle the error.