search
HomeWeChat AppletMini Program DevelopmentHow to monitor events when jumping between WeChat applet pages

Abstract: In the development process of WeChat applet, we will definitely encounter the need to jump between pages, so how to monitor the events between page jumps? In our previous article: Research on eLong WeChat Mini Program Framework Components (with source code) as an example, let’s take a look at the events when the mini program jumps between pages...

In the development process of WeChat applet, we will definitely encounter the need to jump between pages. So how to monitor the events between page jumps? We took a previous article: Research on Framework Components of Yilong WeChat Mini Program (source code attached) as an example to take a look at the event mechanism when mini programs jump between pages.

We know that the mini program provides four mechanisms to change the view, including opening a new page, page redirection, page return, and tabBar switching. It hosts the page. life cycle, and provides corresponding life cycle events for the application to facilitate business processing at each stage of the application, but there is no corresponding event mechanism for jumping between pages, for example -

1. Page A opens secondary page B. Page B has done some operations, and it needs to notify page A to do the corresponding processing.
2. Carry some data from page B and return to page A

The above two scenarios are very common and boil down to page How to interact conveniently? Of course, we can achieve the goal by passing parameters or global data objects through page jumps, but there are some restrictions on use (converting parameters or maintaining global objects)!

So the event mechanism is used to solve this problem in the elong applet project . We rewrote navigateToAPI. After 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) can follow the business The demand triggers the event response, and the relevant data is passed as a parameter to the listening callback.
A Page

##BPage

##API

##Event

How to monitor events when jumping between WeChat applet pages##Part of the code is as follows:

    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 the secondary page rendering——



The above is the detailed content of How to monitor events when jumping between WeChat applet pages. For more information, please follow other related articles on the PHP Chinese website!

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools