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!

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Notepad++7.3.1
Easy-to-use and free code editor

Atom editor mac version download
The most popular open source editor

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.