WeChat Applet
Mini Program Development
How to implement parameter passing from child to parent in WeChat applet (page communication)How to implement parameter passing from child to parent in WeChat applet (page communication)
This article will help you understand how the sub-page in the WeChat applet passes parameters to the parent page. I hope it will be helpful to you!

How to pass parameters from a WeChat mini program subpage to the parent page
Sometimes when we are working on a WeChat mini program project, we will encounter The following situation: there is a list page with a filter condition. After clicking, it will jump to the page and select the condition. After selecting, return to the list page and query the data according to the filter condition. Generally, more often than not, what we see is that filtering conditions are processed through pop-up boxes. So if we want this interactive method of jumping to a page, how do we pass parameters from the child page to the parent page?
【Related learning recommendations: 小program development tutorial】
Questions
- wx.navigateBack cannot carry parameters, and the child page cannot pass parameters to the parent page.
Sub-page operates the data of the parent page
Pay attention here, we are talking about the sub-page operating the data of the parent page.
There is a getCurrentPages API in the official documentation (the official website description is as follows):
PageObject[] getCurrentPages() gets the current page stack. The first element in the array is the homepage, and the last element is the current page.
- Do not try to modify the page stack, as this will cause routing and page status errors.
- Do not call
getCurrentPages()duringApp.onLaunch, whenpagehas not been generated yet.
Through the getCurrentPages API, we can get the data of the page stack, so we can get the specified page. By modifying the parent page data on the child page, we You can realize the function of passing parameters from the child page to the parent page.
const pages = getCurrentPages(); const gotoPage = pages[pages.length - 1];
So pages[pages.length - 1] is the current page, and the parent page is pages[pages.length - 2], and so on, we Other ancestor pages can be obtained.
Then use the setData method gotoPage.setData({xxx: ''}) to modify and set the data of the parent page, so that the child page can be passed to the parent page The purpose of the parameter. Then use wx.navigateBack to return to the page.
Other solutions
- Component
- Pop-up box
Like ours As mentioned at the beginning of the article, if we need to pass parameters from the child page to the parent page, we can display the content in the form of a pop-up box. After selecting the corresponding data, hide the current pop-up box or component.
For more programming-related knowledge, please visit: Introduction to Programming! !
The above is the detailed content of How to implement parameter passing from child to parent in WeChat applet (page communication). For more information, please follow other related articles on the PHP Chinese website!

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

Atom editor mac version download
The most popular open source editor

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

Zend Studio 13.0.1
Powerful PHP integrated development environment

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

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





