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!