1e41f4b71Sopenharmony_ci# Lifecycle Definition 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci> **NOTE** 4e41f4b71Sopenharmony_ci> 5e41f4b71Sopenharmony_ci> This component is supported since API version 5. Updates will be marked with a superscript to indicate their earliest API version. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ciA range of lifecycle callbacks are provided for custom components, including **onInit**, **onAttached**, **onDetached**, **onLayoutReady**, **onDestroy**, **onShow**, and **onHide**. You can use these callbacks to manage the internal logic of your custom components. The following describes the times when the lifecycle callbacks are invoked. 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci| Attribute | Type | Description | Invoked When | 12e41f4b71Sopenharmony_ci| ------------- | -------- | ------------------ | ------------------------------------------------------------ | 13e41f4b71Sopenharmony_ci| onInit | Function | Custom component initialization | The custom component is created. This callback is invoked once.| 14e41f4b71Sopenharmony_ci| onAttached | Function | Custom component loading | The custom component is added to the **\<Page>** component tree. When this callback is invoked, related data can be displayed during the lifecycle in scenarios such as image loading and animation playback.| 15e41f4b71Sopenharmony_ci| onLayoutReady | Function | Component layout completion| Layout calculation, including content size and position adjustment, is complete for the custom component.| 16e41f4b71Sopenharmony_ci| onDetached | Function | Custom component detachment | The custom component is detached. It is usually used to stop animation or asynchronous logic execution. | 17e41f4b71Sopenharmony_ci| onDestroy | Function | Custom component destruction | The custom component is destroyed. It is usually used to release resources. | 18e41f4b71Sopenharmony_ci| onShow | Function | Page display of a custom component| The page where the custom component is located is displayed. | 19e41f4b71Sopenharmony_ci| onHide | Function | Page hiding of a custom component| The page where the custom component is located is hidden. | 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci 22e41f4b71Sopenharmony_ci## Example 23e41f4b71Sopenharmony_ci 24e41f4b71Sopenharmony_ci```html 25e41f4b71Sopenharmony_ci<!-- comp.hml --> 26e41f4b71Sopenharmony_ci<div class="item"> 27e41f4b71Sopenharmony_ci <text class="text-style">{{ value }}</text> 28e41f4b71Sopenharmony_ci</div> 29e41f4b71Sopenharmony_ci``` 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci```js 32e41f4b71Sopenharmony_ci//comp.js 33e41f4b71Sopenharmony_ciexport default { 34e41f4b71Sopenharmony_ci data: { 35e41f4b71Sopenharmony_ci value: "Create a component." 36e41f4b71Sopenharmony_ci }, 37e41f4b71Sopenharmony_ci onInit() { 38e41f4b71Sopenharmony_ci console.log("Component created.") 39e41f4b71Sopenharmony_ci }, 40e41f4b71Sopenharmony_ci onAttached() { 41e41f4b71Sopenharmony_ci this.value = "Load the component." 42e41f4b71Sopenharmony_ci console.log ("Component loaded.") 43e41f4b71Sopenharmony_ci }, 44e41f4b71Sopenharmony_ci onShow() { 45e41f4b71Sopenharmony_ci console.log ("Page displayed.") 46e41f4b71Sopenharmony_ci }, 47e41f4b71Sopenharmony_ci onHide() { 48e41f4b71Sopenharmony_ci console.log ("Page hidden.") 49e41f4b71Sopenharmony_ci } 50e41f4b71Sopenharmony_ci} 51e41f4b71Sopenharmony_ci``` 52