当前位置:网站首页>Applets: lifecycle

Applets: lifecycle

2022-07-28 06:54:00 Like Feynman%

1. What is life cycle

Life cycle refers to the creation of an object from --》 function --》--》 The whole stage of destruction , The emphasis is on a time period

We can Startup of wechat applet , Express The beginning of the life cycle

Close the applet , Indicates the end of the life cycle

The process of running an intermediate applet , Is the life cycle of the applet

2. Classification of life cycle

In the applet , The life cycle is divided into two categories , Namely :

  1. Application life cycle
  2. Page lifecycle   

The life cycle range of the page is relatively small , The application life cycle is relatively large

2. What is a life cycle function

  Life cycle function : It refers to the built-in functions provided by the applet framework , With the life cycle , Automatically execute in order

The function of life cycle function : Allow programmers to at a specific point in time , Perform certain operations . for example : When the page is just loaded , Can be in onLoad Initialize the data of the page in the life cycle function

Be careful : Life cycle emphasizes time period , The life cycle function emphasizes the point in time

2.1 Classification of life cycle functions

  1. Apply lifecycle functions
  •   It refers to that the applet is starting --》 function --》 Those functions called in turn during destruction
  • stay app.js In a statement
  • //app.js file 
    App({
        // When the applet is initialized , Execute this function , The trigger of the overall situation is in turn , Can do some initialization work 
        onLaunch:function(options){},
        // Applet startup , Or trigger when you cut into the foreground display from the background 
        onShow:function(options){},
        // Applet startup , Or trigger when you switch from the foreground to the background display 
        onHide:function(){},
    })

  1. Page lifecycle function
  • On page .js The document states
  • Page({
        // Monitor page loading , A page is called only once 
        onLaunch:function(options){},
        // Monitor page display 
        onShow:function(){},
        // Listen for the first rendering of the page , A page is called only once 
        onReady:function(){},
        // Small monitoring page hidden 
        onHide:function(){},
        // Monitor page uninstall , A page is called only once 
        onUnload:function(){},
    })
    

原网站

版权声明
本文为[Like Feynman%]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/209/202207280519281353.html