beforeCreate
Called immediately when the instance is initialized, after props resolution, before processing other options such as
data() or computed.Note that the setup() hook of Composition API is called before any Options API hooks, even beforeCreate().At this stage:- Props have been resolved
- Data, computed properties, methods, and watchers have not been set up yet
- The component instance exists, but reactive state is not available
created
Called after the instance has finished processing all state-related options.When this hook is called, the following have been set up:
- Reactive data
- Computed properties
- Methods
- Watchers
$el property will not be available yet.This is a good place to perform data fetching or set up subscriptions.Example:beforeMount
Called right before the component is to be mounted.When this hook is called:
- The component has finished setting up its reactive state
- The render function is about to be called for the first time
- No DOM has been created yet
mounted
Called after the component has been mounted.A component is considered mounted after:
- All of its synchronous child components have been mounted (does not include async components or components inside
<Suspense>trees) - Its own DOM tree has been created and inserted into the parent container
- Accessing the DOM via
$elor refs - Integrating with non-Vue libraries that require DOM access
- Starting timers or intervals
- Setting up subscriptions
beforeUpdate
Called right before the component is about to update its DOM tree due to a reactive state change.This hook can be used to access the DOM state before Vue updates the DOM. It is also safe to modify component state inside this hook.This hook is not called during server-side rendering.Example:
updated
Called after the component has updated its DOM tree due to a reactive state change.A parent component’s updated hook is called after that of its child components.This hook is called after any DOM update of the component, which can be caused by different state changes. If you need to access the updated DOM after a specific state change, use
nextTick() instead.This hook is not called during server-side rendering.Warning: Do not mutate component state in the updated hook - this will likely lead to an infinite update loop!Example:beforeUnmount
Called right before a component instance is to be unmounted.When this hook is called:
- The component instance is still fully functional
- All child components are still mounted
unmounted
Called after the component has been unmounted.A component is considered unmounted after:
- All of its child components have been unmounted
- All of its associated reactive effects (render effect and computed / watchers created during
setup()) have been stopped
errorCaptured
errorCaptured
(err: Error, instance: ComponentPublicInstance | null, info: string) => boolean | void
Called when an error from any descendent component has been captured.The hook receives three arguments:
- The error object
- The component instance that triggered the error
- A string specifying the error source type
false to stop the error from propagating further. See error propagation details below.Error Propagation Rules:By default, all errors are sent to the application-level app.config.errorHandler if it is defined, so that these errors can be reported to an analytics service in a single place.If multiple errorCaptured hooks exist on a component’s inheritance chain or parent chain, all of them will be invoked on the same error, in the order from bottom to top. This is similar to the bubbling mechanism of native DOM events.If the errorCaptured hook itself throws an error, both this error and the original captured error are sent to app.config.errorHandler.An errorCaptured hook can return false to prevent the error from propagating further. This essentially says “this error has been handled and should be ignored.” It will prevent any additional errorCaptured hooks or app.config.errorHandler from being invoked for this error.Example:renderTracked
Called when a reactive dependency has been tracked by the component’s render effect.This hook is development-mode-only and not called during server-side rendering.The event object contains information about which dependency was tracked.Example:
renderTriggered
Called when a reactive dependency triggers the component’s render effect to re-run.This hook is development-mode-only and not called during server-side rendering.The event object contains information about which dependency triggered the update.Example:
activated
Called when a component instance is inserted into the DOM as part of a tree cached by
<KeepAlive>.This hook is not called during server-side rendering.This hook is only applicable to components wrapped by <KeepAlive>. It is called each time a cached component is re-activated.Example:deactivated
Called when a component instance is removed from the DOM as part of a tree cached by
<KeepAlive>.This hook is not called during server-side rendering.This hook is only applicable to components wrapped by <KeepAlive>. It is called each time a component is deactivated and cached.Example:serverPrefetch
Async function to be resolved before the component instance is rendered on the server.If the hook returns a Promise, the server renderer will wait for that Promise to resolve before rendering the component.This hook is only called during server-side rendering and can be used to perform server-only data fetching.Example: