How to Listen for events during page jumps of WeChat applets

Source: Internet
Author: User
How does one listen to events during the development of small programs during inter-page jump? we may need to jump between pages. how does one listen to events between page jumps? In our previous article: the study of the iron mini program framework component (with source code) is used as an example to take a look at the event mechanism when the applet jumps between pages.

We know that the applet provides four ways to change the view, including opening a new page, page redirection, Page return, and tabBar switching, hosting the Page lifecycle, it also provides corresponding lifecycle events for applications to facilitate business processing at various stages of the application, but there is no corresponding event mechanism for page redirection between pages, such --

1. when page A opens Page B and page B performs some operations, you must notify page A to perform corresponding processing.
2. carry some data from page B and return to page.

These two scenarios are very common. The reason is how to easily interact between pages. of course, we can achieve this through page jump passing parameters or global data objects, however, there are some limitations in use (conversion parameters or maintenance of global objects )!

Therefore, the event mechanism is used in the elong applet project to solve this problem. We have rewrittenNavigateToAPIAfter Page A calls this interface to jump to the page, the method returns an event object event to page A. this object can register custom events, and the target page (page B) event Response can be triggered according to business requirements, and relevant data can be passed to the listener as a parameter.
Page

[AppleScript]View plain text Copy code

    Page({        data: {            userInfo: {}        },        navigateToHttp: function () {            var event = api.Navigate.go({                url: '../http/index',                params: {                    name: 'billy'                }            });            event.on("listok", function (params) {                console.log(params)            });        },        navigateToExternalComponent: function () {            var event = api.Navigate.go({                url: '../externalComponent/index'            });        },        navigateToInternalComponent: function () {            var event = api.Navigate.go({                url: '../internalComponent/index'            });        },        navigateToPartComponent: function (params) {            var event = api.Navigate.go({                url: '../partComponent/index'            });        },

Open Level 2 page --

The above is a detailed description of how to listen to events for page jumps between applets. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.