What are the life cycles of WeChat Mini Program custom components?

The life cycle functions of WeChat Mini Program custom components are divided into three categories:

  • Lifecycle functions executed on creation,
  • Lifecycle functions executed on update and
  • A lifecycle function to execute on destruction.

The following are the specific life cycle functions and their trigger timing:

Lifecycle functions executed on creation:

  1. created: Executed when the component instance has just been created, and the component data is not bound to the view at this time;
  2. attached: Executed when the component instance enters the page node tree, node information and context information can be obtained, but not rendered;
  3. ready: Executed after the component rendering is completed, and page operations can be performed.

Lifecycle functions executed on update:

  1. moved: executed when the component instance is moved to a new location in the node tree;
  2. detached: Executed when the component instance is removed from the page node tree.

Lifecycle functions executed on destruction:

  1. error: execute when an error is reported inside the component;
  2. pageLifetimes: The life cycle function corresponding to the page, for example show, when the page is displayed, the update time is determined by the page;
  3. detached: Executed when the component instance is removed from the page node tree

It should be noted that the life cycle functions of custom components are different from the life cycle functions of applet pages. When writing components, you need to pay attention to the execution order and timing of each life cycle function, and perform corresponding operations and processing according to actual needs. At the same time, in the life cycle function of the component, you can also use the this.setData method to update the data of the component, so as to realize the update and interaction effect of the view.

Guess you like

Origin blog.csdn.net/hyqhyqhyqq/article/details/129738620