Wechat applet returns to the previous page to pass parameters and refresh process analysis


This article mainly introduces the wechat applet to return to the previous page to pass parameters and refresh the process of parsing. The sample code is introduced in great detail in this article, which has a certain reference learning value for everyone’s study or work. Friends in need can refer to it


The onload (options) method of wechat applet is only loaded once in the whole life cycle, that is, when you enter the next page and return, it will not be triggered again, so it is not feasible for you to return URL to pass parameters.


Now there is such a demand: a product payment page, click the coupon volume to enter the coupon list page, select the coupon and return to the payment page with the data.


1、 The method used is the page stack of small programs. If you are interested, you can print the contents of pages, which is the track array of your page Jump. The last item is the current page, and the penultimate is the previous page. It’s easy to understand, because it stopped on the current page, and it must be the last one

//Get page stack
let pages = getCurrentPages();
//Get the required page
let currPage = pages[pages.length - 1];// Current page
let prevPage = pages[pages.length -2];// previous page

2、 On the payment page, put the data that needs to be refreshed again into Onshow () method, and those that do not need to be refreshed into onload () method


1. Our goal is to render the coupon data to the payment page, so when you click the coupon on the coupon page, you can get the previous page (that is, the payment page) through the page stack, and add this data to the data of the payment page dynamically

//Get page stack
let pages = getCurrentPages();
//Get the required page
let prevPage = pages[pages.length -2];// previous page
  yourD ata:yourData , // the data you need to pass

2. Put the data to be refreshed into the Onshow () method

//This shows how to get the options in the onload method of the current page in the Onshow method
  let pages = getCurrentPages();
  let currPage = pages[pages.length - 1];
  //The options of the current page, what do you mean, is that you may need to refresh a function, but its parameters are just the passed parameters

After you click on the coupon page, because your data has been saved to the payment page, you can directly get the data you need in the data after you return to the payment page and perform the operations you need.

OK, that’s it.

The above is the whole content of this article, I hope to help you learn, and I hope you can support developer more.

Recommended Today

Java daemon thread

catalogue 1、 What is a daemon thread 2、 Why do I need a daemon thread 3、 How to use 4、 Role and application scenario of daemon thread 1、 What is a daemon thread Before talking about daemon threads, let’s talk about what user threads are. User thread: the ordinary thread we usually create。 Daemon thread: […]