What is the execution order of the lifecycle of Uniapp?

The execution order of the uni-app lifecycle is as follows:

  1. The beforeCreate hook is called after the instance is initialized, but before data observation and event setup.
  2. After creation, this is called when the instance has finished data observation, computed properties, and methods, but has not yet been mounted to the DOM.
  3. beforeMount: called before the instance is mounted, when the template is about to be compiled and data in the template will be replaced with actual data.
  4. mounted: This is called after the instance has been mounted to the DOM, allowing for DOM operations to be performed.
  5. beforeUpdate: called before reactive data is updated, happening before the virtual DOM is re-rendered and patched.
  6. This is called after the virtual DOM has been re-rendered and patched, indicating that the component has been updated and is ready for further operations.
  7. beforeDestroy: Called before the instance is destroyed, at this point the instance is still fully usable.
  8. Destroyed: called after the instance is destroyed, at this point all directives and observers have been unbound, and all event listeners have been removed.

It is important to note that there may be slight differences in the lifecycle hook functions mentioned above when used in small programs, H5, Apps, WeChat mini programs, and Alipay mini programs written in uni-app. Adjustments can be made based on actual development needs.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds