Jump from page a to page b, and return to page a from page b. (Reason for monitoring: Sometimes we do related operations on page b, and when clicking back on page b, we need to change the data on page a accordingly)
app.json
App({
globalData: {
show:false,//利用这个变量实现监听
})
a page json
const app = getApp();//引用全局变量,获取雇主的openid
Page({
onShow: function () {
if(app.globalData.show){
wx.showModal({
title: '恭喜你!你已经实现了返回按钮的监听',
content: '这是一个模态弹窗',
success (res) {
if (res.confirm) {
console.log('用户点击确定')
} else if (res.cancel) {
console.log('用户点击取消')
}
}
})
}
})
b page json
Page({
/**
* 生命周期函数--监听页面显示
*/
onShow : function() {
app.globalData.show = true;
console.log("onshow");
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide : function() {
app.globalData.show = false;
console.log("onhide");
},
)}
If there is any offense, please contact and delete it immediately. thanks, thanks.