Home> Web Front-end> uni-app> body text

Let's talk about the triggering methods of all pages of uniapp

PHPz
Release: 2023-04-18 14:16:06
Original
1818 people have browsed it

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:

  1. onLaunch: Application Triggered when the program starts, including page jumps and other operations.
  2. onShow: Triggered when the application enters the foreground. In this method, you can load page data, refresh the page and other operations.
  3. onHide: Triggered when the application enters the background. In this method, page data and other operations can be saved.
  4. onError: Triggered when an error occurs in the application. The error can be handled in this method.
  5. onUniNViewMessage: When the page uses the uni-nvue component, you can listen to this method to obtain the message passed by the sub-component.
  6. 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:

  1. onLoad: Triggered when the page is initialized. In this method, you can obtain the parameters passed by the page and other operations.
  2. onReady: Triggered when the initial rendering of the page is completed. In this method, you can operate the page DOM and other operations.
  3. onUnload: Triggered when the page is closed. Cleaning operations can be performed in this method.
  4. onPullDownRefresh: Triggered when the user pulls down the page. In this method, the page data can be refreshed.
  5. onReachBottom: Triggered when the user slides the bottom of the page. More data can be loaded in this method.
  6. onResize: Triggered when the page size changes. In this method, you can adapt to different screen sizes.
  7. 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:

  1. getCurrentPages: Get the current page stack instance.
  2. navigateTo: Jump to a page within the application.
  3. redirectTo: Close the current page and jump to a page within the application.
  4. switchTab: Jump to a tab page within the application.
  5. reLaunch: Close all pages and reopen a page in the app.
  6. navigateBack: Return to the previous page or multi-level page.
  7. showLoading: Display the loading prompt box.
  8. hideLoading: Hide the loading prompt box.
  9. showToast: Display message prompt box.
  10. 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!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!