1. Life cycle of applets:
The Page() function is used to register a Page. Accepts an object parameter that specifies the page’s initial data, lifecycle functions, event handlers, and so on.
OnLoad lifecycle function – listens for page loads
OnReady lifecycle function – listens for the page to finish rendering for the first time
OnShow lifecycle function – listens for page display
OnHide lifecycle function – listens for page hiding
OnUnload Lifecycle function – Listens for page unload
OnPullDownRefresh page-related event handler – listens for user pulldownRefresh actions
OnReachBottom Handler for the pull bottom event on the page
The onShareAppMessage user clicks in the upper right corner to forward the message
OnPageScroll Handler of the page scroll trigger event
OnTabItemTap Triggered when a TAB page is clicked
Life cycle function onLoad: a page load is called only once. You can get the query parameter in onLoad to open the current page. OnShow: Page display is called every time a page is opened. OnReady: a page is called only once after its first rendering, indicating that the page is ready to interact with the view layer. Settings such as wx.setNavigationBarTitle should be set after onReady. See life cycle onHide: Page hide is called when navigateTo or bottom TAB is switched. OnUnload: Called when a page is unloaded by redirectTo or navigateBack.
2. Applets custom components:
Note: ID selectors, attribute selectors, and tag name selectors should not be used in component WXSS.
In the js file of a custom Component, you use Component() to register the Component and provide its property definitions, internal data, and custom methods.
Component property values and internal data will be used for component WXML rendering, where property values can be passed in from outside the component. See the Component constructor for more details.
Details for attention
Some details to note:
- Because WXML node label names can only be lowercase letters, hyphens, and underscores, custom component label names can only contain these characters.
- Custom components can also refer to custom components in a manner similar to the way pages refer to custom components (using
usingComponents
Field). - The name of the root directory where custom components and pages reside cannot be prefixed with wx-; otherwise, an error message will be reported.
Note that whether or not you use usingComponents in the page file will make the prototype of the page’s this object slightly different, including:
- use
usingComponents
The prototype of the page is inconsistent with when not in use, i.eObject.getPrototypeOf(this)
The results are different. - use
usingComponents
There will be more methods, such asselectComponent
。 - For performance reasons, use
usingComponents
When,setData
Content is not directly copied deep, i.ethis.setData({ field: obj })
后this.data.field === obj
. (Deep copy occurs when the value is passed between components.)
If the page is complex, it is recommended to re-test the usingComponents definition section when adding or removing it.
3. Jump to other programs:
* * to open the other small program: wx navigateToMiniProgram (Object Object) * * returns on a small program: wx. NavigateBackMiniProgram (Object Object)