小程序返回上一页后刷新
经过测试,onshow在onload之后。
在首次进入时,list中为空,在onshow中直接跳过。
在返回上一页时,list中数据是不为空的,则需要执行onshow中的方法。
onShow: function () { var that = this; console.log("show",that.data.list.length); if(that.data.list.length>0){ that.setData({ openid: app.globalData.openid, root: app.globalData.root, pageIndex:1 }) that.query(that.data.openid, that.data.pageIndex, that.data.pageSize, that.data.activeIndex,true) } },
onLoad: function (options) { var that = this; that.setData({ openid: app.globalData.openid, root: app.globalData.root }) that.query(that.data.openid, that.data.pageIndex, that.data.pageSize, that.data.activeIndex,false) }, query: function (openid, index, size, type,isRefesh) { var that = this; var end; console.log("type:"+type); if (type == 0) { end = that.data.isEnd; } else { end = that.data.isEnd1; } var isid = that.data.activeIndex; type = parseInt(type); wx.showNavigationBarLoading() if (end == false) { wx.showLoading({ title: '正在加载中', }) wx.request({ url: app.globalData.root + "service/WeChatParent.asmx/GetMessageList", data: { openid: openid, type: type + 1, pageIndex: index, pageSize: size, key: '', stime: '', etime: '' }, method: 'post', success: function (datas) { var resuJson = JSON.parse(datas.data.d); console.log(resuJson); if (resuJson.list.length == 0 ) { that.setData({ dataNull: true }) } else { that.setData({ dataNull: false }) } if (resuJson.end == true) { if (type == 0) { that.setData({ isEnd: true }) } else { that.setData({ isEnd1: true }) } } if (isid == 0) {//话机留言 if(isRefesh){ that.setData({ list: resuJson.list, pageIndex: 1, }) }else{ that.setData({ list: that.data.list.concat(resuJson.list), pageIndex: that.data.pageIndex + 1, }) } } else { that.setData({ list1: that.data.list1.concat(resuJson.list), pageIndex1: that.data.pageIndex1 + 1, }) } wx.hideLoading() } }) } else { wx.showToast({ title: '没有更多数据了' }) } wx.hideNavigationBarLoading() },