uniapp life cycle

As a cross-platform application development framework, Uniapp has a rich life cycle. The following is the life cycle of Uniapp:

1. Application life cycle

The application life cycle refers to the entire process from startup to shutdown of the application, including application startup, front-background switching, and exit. Uniapp provides the following lifecycle hook functions:

  • onLaunch: Triggered when the application starts, only when the application starts for the first time.
  • onShow: Triggered when the application enters the foreground, and the method and scene value of the application can be obtained.
  • onHide: Triggered when the app enters the background.
  • onError: Triggered when an error occurs in the application, which can be used to capture and process error information.
  • onUniNViewMessage: Listen for messages from the nvue page.

2. Page life cycle

The page life cycle refers to the entire process from creation to destruction of the page, including creation, display, hiding, and destruction of the page. Uniapp provides the following lifecycle hook functions:

  • onInit: Triggered when the page is initialized, page parameters and data can be obtained.
  • onLoad: Triggered when the page is loaded, data initialization and network requests can be performed.
  • onReady: Triggered when the page rendering is completed, and operations such as page animation and interaction can be performed.
  • onShow: Triggered when the page is displayed, it can handle operations such as the display effect and animation of the page.
  • onHide: Triggered when the page is hidden, and can handle operations such as page hiding effects and animations.
  • onUnload: Triggered when the page is destroyed, and can perform operations such as resource release and cleanup.

3. Component life cycle

Component lifecycle refers to the entire process from creation to destruction of components, including creation, update, destruction, etc. of components. Uniapp provides the following lifecycle hook functions:

  • beforeCreate: Triggered before the component instance is created, and the data and methods of the component have not been initialized yet.
  • created: Triggered after the component instance is created, at this time the data and methods of the component have been initialized.
  • beforeMount: Triggered before the component is rendered, and the component has not been rendered on the page at this time.
  • mounted: Triggered after the component is rendered, at this time the component has been rendered on the page.
  • beforeUpdate: Triggered before the component data is updated, and the component data has not been updated yet.
  • updated: Triggered after the component data is updated, at this time the component data has been updated.
  • beforeDestroy: Triggered before the component instance is destroyed, and the data and methods of the component can still be accessed at this time.
  • destroyed: Triggered after the component instance is destroyed. At this time, the data and methods of the component are no longer accessible.

Summarize:

Uniapp provides a wealth of lifecycle hook functions that developers can use and extend as needed. In application development, you need to pay attention to the execution order and timing of lifecycle functions to avoid unnecessary problems and errors.

Guess you like

Origin blog.csdn.net/m0_64590669/article/details/130307866