微信小程序 - 问题 - 返回上一页携带参数(wx.navigateBack(){}方法)

 (1)wx.navigateBack()

 back:function(){
    var pages = getCurrentPages();
    var currPage = pages[pages.length - 1];   //当前页面
    var prevPage = pages[pages.length - 2];  //上一个页面
    //直接调用上一个页面对象的setData()方法,把数据存到上一个页面中去
    prevPage.setData({
      backPageParam:"myTab"
    });
    wx.navigateBack({
      delta: 1
    })
  },

(2)返回的页面

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    that.setData({
      .....
    })
    var userScope = app.getUserScope();

    .....

    if (util.checkParam(that.data.backPageParam)){
      if (that.data.backPageParam =="myTab"){
          that.setData({
            week:2
          })
          console.log("调用mytab")
        //每次切换刷新数据
        that.setData({
          currentPage: 0,
          totalDataCount: 0,
          pics: [],
          dataArray: [],
          sortData: [],
          sortDataArray: [],
          category: 2
        })
        that.getUserPostPictureList()
        that.cyCount()
        }
    }

  },

 

你可能感兴趣的:(微信小程序)