Uniapp is a cross-platform development framework that allows developers to develop applications for WeChat applets, H5, iOS, Android and other platforms at the same time, which greatly facilitates the work of developers. When developing uniapp applications, we often need to trigger methods on different pages to implement some special functions. This article will introduce the triggering methods of all pages of uniapp for developers' reference.
1. Life cycle methods
The uniapp framework provides some life cycle methods, which are triggered at different life cycle stages of the page, as follows:
- onLaunch: Application Triggered when the program starts, including page jumps and other operations.
- onShow: Triggered when the application enters the foreground. In this method, you can load page data, refresh the page and other operations.
- onHide: Triggered when the application enters the background. In this method, page data and other operations can be saved.
- onError: Triggered when an error occurs in the application. The error can be handled in this method.
- onUniNViewMessage: When the page uses the uni-nvue component, you can listen to this method to obtain the message passed by the sub-component.
- onUniNViewLoad: When using the uni-nvue component, you can listen to this method to obtain the loading status of the sub-component.
2. Page life cycle methods
uniapp also provides some page life cycle methods, which are only triggered in the page, as follows:
- onLoad: Triggered when the page is initialized. In this method, you can obtain the parameters passed by the page and other operations.
- onReady: Triggered when the initial rendering of the page is completed. In this method, you can operate the page DOM and other operations.
- onUnload: Triggered when the page is closed. Cleaning operations can be performed in this method.
- onPullDownRefresh: Triggered when the user pulls down the page. In this method, the page data can be refreshed.
- onReachBottom: Triggered when the user slides the bottom of the page. More data can be loaded in this method.
- onResize: Triggered when the page size changes. In this method, you can adapt to different screen sizes.
- onPageScroll: Triggered when the page scrolls. In this method, the sliding effect can be achieved.
3. Other methods
In addition to the above life cycle methods and page life cycle methods, uniapp also provides some common methods for use in different pages, as follows:
- getCurrentPages: Get the current page stack instance.
- navigateTo: Jump to a page within the application.
- redirectTo: Close the current page and jump to a page within the application.
- switchTab: Jump to a tab page within the application.
- reLaunch: Close all pages and reopen a page in the app.
- navigateBack: Return to the previous page or multi-level page.
- showLoading: Display the loading prompt box.
- hideLoading: Hide the loading prompt box.
- showToast: Display message prompt box.
- hideToast: Hide the message prompt box.
The above is a detailed introduction to all page triggering methods in uniapp. Different methods play different roles in different scenarios. Developers need to comprehensively consider business needs and choose appropriate methods to use. At the same time, it should be noted that when using the method, you must follow the usage specifications of the uniapp framework to avoid some common mistakes. I hope this article can be helpful to everyone when developing applications using uniapp.
The above is the detailed content of Let's talk about the triggering methods of all pages of uniapp. For more information, please follow other related articles on the PHP Chinese website!