Home > Article > Web Front-end > An in-depth analysis of the life cycle of uni-app
This article brings you relevant knowledge about the uniapp declaration cycle. It mainly introduces issues related to the application declaration cycle, page life cycle and component life cycle. I hope it will be helpful to everyone.
## Recommended: "uniapp tutorial"
Application life cycleuni-app Support the following application life cycle functions:
Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Triggered when | uni-app initialization is completed (only triggered once globally)
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
When | uni-app starts, or enters the foreground from the background to display
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
When | uni-app enters the background from the foreground
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Triggered when | uni-app reports an error
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Yes | nvue To monitor the data sent by the page, please refer to nvue communicating with vue
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The unhandled Promise rejection event listening function (2.8. 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The page does not have a listening function | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Listening to system theme changes |
Function name | Description | Platform difference description | Minimum version | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
onInit | Listen to the page initialization, its parameters are the same as the onLoad parameters, which are the data passed on the previous page. The parameter type is Object (used for page parameter transfer), and the triggering time is earlier than onLoad | Baidu Mini Program | 3.1.0 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
onLoad | Monitor page loading, the parameter is the data passed on the previous page, the parameter type is Object (used for page parameters), refer to the example |
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
onShow | Listen to the page display. Triggered every time the page appears on the screen, including returning from the lower-level page point to reveal the current page | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The initial rendering of the monitoring page is completed. Note that if the rendering speed is fast, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
## will be triggered before the page entry animation is completed. #Listen page hide | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Listen page unload | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
App, WeChat applet | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
##onTabItemTap |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
WeChat Mini Program, QQ Mini Program, Alipay Mini Program, Baidu Mini Program, H5, App |
onShareAppMessage |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
WeChat applet, QQ applet, Alipay applet, Byte applet, Feishu applet, Kuaishou applet |
onPageScroll |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
nvue does not support it yet |
onNavigationBarButtonTap |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
App, H5 |
onBackPress |
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
app, H5, Alipay applet | ##onNavigationBarSearchInputChanged | Monitor the input content of the native title bar search input box Change event|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1.6.0 | onNavigationBarSearchInputConfirmed | Listen to the native title bar search input box search event, user Fired when the "Search" button on the soft keyboard is clicked. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1.6.0 | onNavigationBarSearchInputClicked | Listen to the native title bar search input box click event (pages.json It will be triggered only when the searchInput configuration in disabled is true) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1.6.0 | onShareTimeline | Listening The user clicks the upper right corner to forward to the circle of friends | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2.8.1 | onAddToFavorites | Monitors the user’s click on the upper right corner Collection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
2.8.1 |
Attribute | Type | Description |
---|---|---|
Number | The distance the page has been scrolled in the vertical direction (unit px) |
Note
, such as frequent page modifications. Because this life cycle is triggered in the rendering layer, on the non-h5 side, js is executed in the logic layer, and there is a loss in communication between the two layers. If the data exchange between the two layers is frequently triggered during the scrolling process, it may cause lag.
cannot be used on
async, which will result in the failure to prevent the default return of
onPageScroll : function(e) { //nvue暂不支持滚动监听,可用bindingx代替 console.log("滚动距离为:" + e.scrollTop); },
onTabItemTap returned json Object description:
Type | Description | |
---|---|---|
String | The serial number of the clicked tabItem, starting from 0 | |
String | The page path of the clicked tabItem | |
String | The button text of the clicked tabItem |
Note
onTabItemTap : function(e) { console.log(e); // e的返回格式为json对象: {"index":0,"text":"首页","pagePath":"pages/index/index"} },
onNavigationBarButtonTap Parameter description :
Type | Description | |
---|---|---|
Number | The subscript of the native title bar button array |
onBackPress Callback parameter object description:
Type | Description | ||
---|---|---|---|
String | The source of triggering the return behavior: 'backbutton' - the navigation bar button in the upper left corner and the Android return key; 'navigateBack' - the uni.navigateBack() method. | Alipay applet does not support returning this field |
函数名 | 说明 | 平台差异说明 | 最低版本 |
---|---|---|---|
beforeCreate | 在实例初始化之后被调用。详见 | ||
created | 在实例创建完成后被立即调用。详见 | ||
beforeMount | 在挂载开始之前被调用。详见 | ||
mounted | 挂载到实例上去之后调用。详见 注意:此处并不能确定子组件被全部挂载,如果需要子组件完全挂载之后在执行操作可以使用$nextTick Vue官方文档 |
||
beforeUpdate | 数据更新时调用,发生在虚拟 DOM 打补丁之前。详见 | 仅H5平台支持 | |
updated | 由于数据更改导致的虚拟 DOM 重新渲染和打补丁,在这之后会调用该钩子。详见 | 仅H5平台支持 | |
beforeDestroy | 实例销毁之前调用。在这一步,实例仍然完全可用。详见 | ||
destroyed | Vue 实例销毁后调用。调用后,Vue 实例指示的所有东西都会解绑定,所有的事件监听器会被移除,所有的子实例也会被销毁。详见 |
推荐:《uniapp教程》
The above is the detailed content of An in-depth analysis of the life cycle of uni-app. For more information, please follow other related articles on the PHP Chinese website!