Mini-program tutorial (article 4), mini-program tutorial Article 4
Basic Framework of Applet development and its restrictions and Optimization
Basic Development Framework (MINA Framework)
└ ── Project-folder /·································· project directory
Pages-pages /···································· · page Directory
│ Choose-index /··································· index page
│ Index ── index. js · index page logic
│ Index ── index. wxml · index page Structure
│ Index ── index. wxss · index page style
│ ─ ── Index. json · index page configuration (partial)
│ └-Logs /··································· · logs page
│ ├-Logs. js · logs page logic
│ ├-Logs. wxml · logs Page Structure
│ └-Logs. wxss · logs Page Style
├-Utils /···································· · Public Script directory
│ └ ── Util. js · tool scripts
├ ── App. js · Application program Logic is used to define the logic of the entire application.
It is used to listen for and process the life cycle functions of applets and declare global variables.
├ ── App. json · application configuration (global) global configuration of the entire Applet
Configure the page on which the applet is composed, and configure the background color of the applet window, etc.
└ ── App. wxss · Application public style is used to set the entire application public Style
1. The app function is a global function used to create an application instance. Each application has its own lifecycle.
2. page is also a global function used to create page objects.
3. wxml is an XML syntax, not an HTML syntax. Simply put: wxml ≈ xml + Event System + template engine
4. The json file is a configuration file created on demand. However, app. json must be created
5. All configuration or settings on the page will take precedence over global configuration or settings, that is, the local configuration will overwrite the global configuration.
6. WXSS has most CSS features and has been expanded and modified at the same time. The size unit (rpx) can be adaptive according to the screen width. Currently, only a few selectors are supported (. class/# id/element, element/: after/: before)
7. the file names in each folder are uniform, with only different suffix names, because the json configuration file will eventually integrate all the pages into one page, with the same name, associate the page with the logic js and style.
8. when the application starts, the app under the project directory is automatically executed. js file in app. js creates an application instance by calling the global App ([option]) method. Some specific methods specified by parameters are executed at specific execution times, that is, the lifecycle event method. App. js and app. json are required.
Life Cycle functions of a Applet
Attribute
|
Type |
Description |
Trigger time |
OnLaunch |
Function |
Life Cycle Function-listens to applet Initialization |
When the applet Initialization is complete, onLaunch is triggered (only once globally) |
OnShow |
Function |
Life Cycle Function-listener for applet display |
OnShow is triggered when the applet is started or enters the foreground display from the background. |
OnHide |
Function |
Lifecycle functions-monitor hidden applets |
When a applet enters the background from the foreground, onHide is triggered. |
Others |
Any |
Developers can add any function or data to the Object parameter, and use this to access |
Lifecycle Functions
A page is called only once.
The parameters on the receiving page can be used to obtain the query in wx. navigateTo, wx. redirectTo, and <navigator/>.
A page is called only once, indicating that the page is ready and can interact with the view layer.
Set the interface settings, such as wx. setNavigationBarTitle, after onReady.