Wechat applet monitors the return button of wx.navigateTo

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");
  },
)}

Reference for this article: https://blog.csdn.net/qq_38815953/article/details/81813743?utm_source=blogxgwz2&ops_request_misc=&request_id=&biz_id=102&utm_term=%E5%BE%AE%E4%BF%A1%E5%B0%8F% E7%A8%8B%E5%BA%8F%E7%9B%91%E5%90%ACnavigator%E8%BF%94%E5%9B%9E&utm_medium=distribute.pc_search_result.none-task-blog-2~all~ sobaiduweb~default-5-81813743.first_rank_v2_pc_rank_v29&spm=1018.2226.3001.4187

If there is any offense, please contact and delete it immediately. thanks, thanks.

Guess you like

Origin blog.csdn.net/qq_46586512/article/details/120194922