Parameters to the App constructor
Parameter Attribute Type description
- OnLaunchFunction Fires onLaunch when the applet is initialized (globally only once)
- OnShow Function The onShow Function is triggered when the applets start or are displayed from the background to the foreground
- OnHide Function The onHide Function is triggered when an applet enters the background from the foreground
- OnError Function When a script error occurs or an API call fails, onError is raised and an error message is displayed
- Other fields can add any function or data to the Object parameter, which can be accessed by calling this in the App instance
Page life cycle
Parameter Attribute Type description
- Data Object Initial data for the page
- OnLoad Function life cycle Function – listens for page loads before onShow and onReady
- OnReady Function Life cycle Function – listens for the page to complete the first rendering
- OnShow Function Life cycle Function – Listens for page display and fires events before onReady
- OnHide Function Life cycle Function – listens for page hiding
- OnUnloadFunction Lifecycle function – Listens for page unloading
- OnPullDownRefresh Function A page-related event handler that listens for user pulldownRefresh actions
- OnReachBottom Function A handler for the pull bottom event on the page
- OnShareAppMessage Function The user clicks in the upper right corner to forward
- OnPageScroll Function Handler for the page scroll trigger event
- Any can add Any functions or data that can be accessed by this in other functions of the Page instance
When the Page is first loaded, the wechat client will issue an onLoad event to the Page instance. The onLoad method defined by the Page constructor parameter will be called. OnLoad will only trigger once before the Page is destroyed.
After the Page is displayed, the onShow method defined by the Page constructor argument is called, and the onShow method of the current Page is usually called when the Page is returned from another Page.
The onReady method defined by the Page constructor parameter is called when the Page is first rendered. OnReady fires only once before the Page is destroyed. OnReady indicates that the Page is ready to interact with the view layer at the logical level.
The onHide method defined by the Page constructor argument is called when the Page is not visible, which is triggered when you switch to another Page using wx.navigateTo and the bottom TAB is switched.
When the current Page returns to another Page using wx.redirectTo or wx.navigateBack, the current Page is destroyed and recycled by the wechat client. The onUnload method defined by the Page constructor parameter is called.
// Order of execution; OnLoad and onReady are executed only once before the page is destroyed. OnLoad > onShow > onReady > onHide > onUnloadCopy the code
Native component communication
Some native components support using context to update components. Unlike setData, updating components with context does not involve a re-rendering process, nor does data communication. In the data communication process of setData, data is forwarded from the logical layer through the native layer, transmitted to the WebView of the view layer, and then transmitted to the component after a series of rendering steps. When context is used, data is directly transmitted to the component after being transmitted from the logical layer to the native layer, which can significantly reduce the transmission delay.