A brief introduction to the uniapp life cycle

1. Application life cycle (can only be monitored in App.vue)

name effect
onLaunch Triggered when uni-app initialization is completed (only triggered once globally)
onShow When uni-app starts, or enters the foreground display from the background (triggered when the page is displayed)
onHide Triggered when uni-app enters the background from the foreground (hide/exit the page)
onError Triggered when uni-app reports an error
onUniNViewMessage Monitor the data sent by the nvue page
onUnhandledRejection Reject event listener function for unhandled Promise
onPageNotFound There is no listening function on the page
onThemeChange Monitor system theme changes

2. Page life cycle

name effect
onInit Monitoring page initialization, its parameters are the same as onLoad parameters, and the triggering time is earlier than onLoad
onLoad Monitor page loading, its parameters are the data passed on the previous page, and the parameter type is Object (used for page parameter passing)
onShow The monitoring page is displayed. Triggered every time the page appears on the screen, including returning to the current page from the subordinate page point
onReady The initial rendering of the monitoring page is completed. Note that if the rendering speed is fast, it will be triggered before the page entry animation is completed.
onHide Listening page hidden
onUnload Monitor page uninstallation
onResize Monitor window size changes
onPullDownRefresh Monitor the user's pull-down action, generally used for pull-down refresh
onReachBottom Event when the page scrolls to the bottom (not scroll-view to the bottom), often used to pull down the next page of data
onTabItemTap Triggered when tab is clicked, parameter is Object
onShareAppMessage User clicks on the upper right corner to share
onPageScroll Monitor page scrolling, the parameter is Object
onNavigationBarButtonTap Listen to the native title bar button click event, the parameter is Object
onBackPress Monitor page return
onNavigationBarSearchInputChanged Monitor the input content change event of the native title bar search input box
onNavigationBarSearchInputConfirmed Monitor the search event of the native title bar search input box, which is triggered when the user clicks the "Search" button on the soft keyboard
onNavigationBarSearchInputClicked Monitor the click event of the native title bar search input box (triggered only when the searchInput configuration disabled in pages.json is true)
onShareTimeline Monitor the user's click on the upper right corner to forward to Moments
onAddToFavorites Monitor the user's click on the collection in the upper right corner

3. Component life cycle is the same as vue life cycle

name effect
beforeCreate Called after instance initialization
created Called immediately after the instance is created
beforeMount Called before the mount begins
mounted Called after mounting to the instance
beforeUpdate Called when data is updated
updated Called after data is updated
beforeDestroy Called before the instance is destroyed. At this step, the instance is still fully available
destroyed Called after the Vue instance is destroyed. After this call, everything pointed to by the Vue instance will be unbound, all event listeners will be removed, and all child instances will be destroyed.

Guess you like

Origin blog.csdn.net/weixin_44309299/article/details/127568940