Mini program supports development using React, but it is slightly different from using React in the browser.
#The entry component
For each Mini Program, a Mini Program instance needs to be registered by calling the App method via app.js, to link the lifecycle callback function, error listening function, page not found listening function, etc.
A Mini Program has only one app instance, which is shared to all pages. Developers can obtain the globally unique app instance by using the getApp method, and then obtain data in the app or call a function registered with App by the developers.
We can add a new app.json file for global configuration.
The configuration specification is based on the global configuration of the mini program.
Trigger when the app is launched.
Triggered when the program is launched, or when the foreground is cut.
Triggered when the application cuts the background.
Listens for Mini Program error events. Such as a script error or API Call error, etc. The parameter err points to the thrown error.
For each page of a Mini Program, a page instance needs to be registered by calling the Page method via the js file corresponding to the page, to specify the initial data of the page, the lifecycle callback function, the event processing function.
Fired whenever tab item tapped
|index||String||the index of the tab item starting from 0|
|pagePath||String||the path of the tab item|
|text||String||the text value of the tab item|
For each page file (e.g. . /pages/index/index.js), we can add a new . /pages/index/index.json file for page configuration.
In the page component, you can get the current page's routing parameters via getCurrentInstance().router.
Page routing parameters can be accessed during this lifecycle by calling getCurrentInstance().router.
From this lifecycle mini program has already rendered DOM nodes to the rendering layer using APIs.
Triggered when the page is displayed/cut to the foreground.
Triggered when the page is hidden/cut to the background.
Listens for Mini Program error events. Such as a script error or API Call error, etc.
Listens user swiping the page.
Parameter Object object:
|scrollTop||Number||Scroll distance in the vertical direction (unit: px)|
Note: To reduce the impact of triggering of nonessential events on communication between the rendering layer and the logic layer, this method should be defined in page only when necessary. Do not define an empty method. Note: Avoid repeated execution of in onPageScroll that may trigger communication between the rendering layer and the logic layer. Transferring large volume of data each time will result in longer communication time.
A child component in a page
Listens user swiping up to the bottom of the page.
- You can set the trigger distance onReachBottomDistance in the app.json window option or in the Page Configuration.
- This event is only triggered once when the page scrolls within the trigger distance.
A child component in a page
Listen to the user click on the in-page share onbutton assembly open-type="share" Or the upper-right menu "Share" on behavior, or execute
bn.showSharePanel, and customize the share content.
|from||String||Share the source of the event. |
This event handler requires return One Object or Promise, used to customize the sharing content, returns the following:
|title||String||Sharing Title||Current applet name|
|imageUrl||String||Custom picture path, should be network picture path. Support for PNG and JPG.||Use default screenshots|
|path||Function||Sharing path||Current page path Must be based on / Full path to start|
|success||Function||Callback function when the user forwards on|