网页
综合
更新时间 2026-11-13 15:33:00
Composition API: Lifecycle Hooks | Vue.js
自动蜘蛛
vuejs.org
正文约 3481 字
Reactivity: Utilities
Reactivity: Advanced
Dependency Injection
Options: Composition
Syntax Specification
Server-Side Rendering
TypeScript Utility Types
All APIs listed on this page must be called synchronously during the setup() phase of a component. See Guide - Lifecycle Hooks for more details.
Registers a callback to be 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. Note it only guarantees that the component's DOM tree is in-document if the application's root container is also in-document.
This hook is typically used for performing side effects that need access to the component's rendered DOM, or for limiting DOM-related code to the client in a server-rendered application.
This hook is not called during server-side rendering.
Accessing an element via template ref:
Registers a callback to be 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, because multiple state changes can be batched into a single render cycle for performance reasons. 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.
Do not mutate component state in the updated hook - this will likely lead to an infinite update loop!
Accessing updated DOM:
Registers a callback to be 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.
Use this hook to clean up manually created side effects such as timers, DOM event listeners or server connections.
This hook is not called during server-side rendering.
Registers a hook to be called right before the component is to be mounted.
When this hook is called, the component has finished setting up its reactive state, but no DOM nodes have been created yet. It is about to execute its DOM render effect for the first time.
This hook is not called during server-side rendering.
Registers a hook to be 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.
Registers a hook to be called right before a component instance is to be unmounted.
When this hook is called, the component instance is still fully functional.
This hook is not called during server-side rendering.
Registers a hook to be called when an error propagating from a descendant component has been captured.
Errors can be captured from the following sources:
The hook receives three arguments: the error, the component instance that triggered the error, and an information string specifying the error source type.
In production, the 3rd argument (info) will be a shortened code instead of the full information string. You can find the code to string mapping in the Production Error Code Reference.
本页为82搜索生成的网页快照,内容来自站内索引;演示数据的原文链接仅作示例。