Requirements:
As the picture above shows:
- After clicking “Forward notes” on the right page, call wX.navigateback () to exit the stack and return to the upper page, the left page;
- After returning to the left side of the page, you need to refresh the data and send the API request;
Question:
- Under normal circumstances, navigateBack navigation interface of wechat small program will not cause the trigger of life cycle function, cannot pass parameters, re-call API request interface, so as to achieve the demand of data refresh;
Solution:
-
Get the current stack array object;
- let pages=getCurrentPages();
-
Obtain the page object of the previous page: beforePage. Before the navigateBack is executed, the request API function of the page object “beforePage” is executed.
-
Example code:
// Return to the previous page let pages=getCurrentPages(); let beforePage=pages[pages.length-2]; //getNoteDetail for the refresh data function of the previous page; beforePage.getNoteDetail(note); wx.navigateBack({ delta:1, })Copy the code