The WeChat applet determines whether the page returns from other pages. The specific content is as follows:
Customize a tag variable in data, in onLoad
Page({ data: { isNewOpen: true, //Judge whether the current page is newly opened or returned from another page list: [], page: 0 }, onLoad: function() { () }, getList () { // ... }, goDetail (e) { ({ isNewOpen: false }) ({ url: `/pages/detail/detail`, }) }, onShow: function () {if (!) { ({ page: 2, // Page number isClose: true, list: [] }) () } }, })
ps: Let’s look at the WeChat mini program below to determine whether the current page is reopened or returned from other pages
Set variables in the applet to determine whether they are returned from other pages
Declare a variable isClose in the data data, defaulting to true . Used to determine whether it is opened normally or returned from other pages. When clicking on the jump page or closing the applet, the OnHide function will be triggered. In this function, it will be judged that isClose is true, which is normally opened. When jumping the page, first set isClose to false. When the OnHide function is triggered, isClose is flase will not be executed. Enter the page that jumps, and then return it from the page. This is the OnUnload function that triggers the jump. In this function, set a timer. Change isClose to true after 200ms. This way, when closing the applet and entering again, isColse is still true. It is the first time to enter the page when it is judged that it is still true.
Example
data:
data: { isClose:true //Judge whether the current page is open or returned to the page }
Jump to page:
({ isClose:false}) ({ url: '../index/index?', })
onUnload:
/** * Lifecycle function-listening page uninstall */ onUnload: function () { var that =this setTimeout(function () { ({ isClose: true }) }, 200) },
onHide:
/** * Lifecycle function--listening page hidden */ onHide: function () { if () { ('Reopen') } },
onShow:
/** * Lifecycle function--listening page display */ onShow: function () { () if (!) { (); } },
Summarize
The above is the example code for determining whether the WeChat mini program is returned from other pages that the editor introduced to you. I hope it will be helpful to you. If you have any questions, please leave me a message and the editor will reply to you in time. Thank you very much for your support for my website!
If you think this article is helpful to you, please reprint it. Please indicate the source, thank you!