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.
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
- onPageScroll Do not write js with complex interactions in
, 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.
If you want to achieve a transparent gradient of the title bar during scrolling, under App and H5, you can configure the type under titleNView in pages.json to be transparent, for reference. - If you need to scroll the ceiling to fix certain elements, it is recommended to use CSS sticky layout and refer to the plug-in market. There are also other js-implemented ceiling plug-ins in the plug-in market, but their performance is not good. You can search for them by yourself when needed.
- In App, WeChat applet, and H5, you can also use wxs to monitor scrolling, for reference; in app-nvue, you can use bindingx to monitor scrolling, for reference.
- onBackPress
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 is often used to click on the current tabitem, scroll or refresh the current page. If you click on different tabitem, page switching will definitely be triggered.
- If you want to click a tabitem on the App side without jumping to the page, you cannot use onTabItemTap. You can use plus.nativeObj.view to place a block to cover the original tabitem and intercept the click event.
- Alipay mini program platform onTabItemTap is triggered after clicking on a non-current tabitem, so it cannot be used to implement the operation of clicking back to the top
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!

The article discusses debugging strategies for mobile and web platforms, highlighting tools like Android Studio, Xcode, and Chrome DevTools, and techniques for consistent results across OS and performance optimization.

The article discusses debugging tools and best practices for UniApp development, focusing on tools like HBuilderX, WeChat Developer Tools, and Chrome DevTools.

The article discusses end-to-end testing for UniApp applications across multiple platforms. It covers defining test scenarios, choosing tools like Appium and Cypress, setting up environments, writing and running tests, analyzing results, and integrat

The article discusses various testing types for UniApp applications, including unit, integration, functional, UI/UX, performance, cross-platform, and security testing. It also covers ensuring cross-platform compatibility and recommends tools like Jes

The article discusses common performance anti-patterns in UniApp development, such as excessive global data use and inefficient data binding, and offers strategies to identify and mitigate these issues for better app performance.

The article discusses using profiling tools to identify and resolve performance bottlenecks in UniApp, focusing on setup, data analysis, and optimization.

The article discusses strategies for optimizing network requests in UniApp, focusing on reducing latency, implementing caching, and using monitoring tools to enhance application performance.

The article discusses optimizing images in UniApp for better web performance through compression, responsive design, lazy loading, caching, and using WebP format.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

WebStorm Mac version
Useful JavaScript development tools

Atom editor mac version download
The most popular open source editor

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software