小程序——返回上个页面触发事件(onUnload)

//页面销毁前——上传被提交的数据
	onUnload:function(){
		var _this=this;
		let updateStatus = wx.getStorageSync('UpdateStatus');//判断是否有未上传的数据
		if(updateStatus){
			wx.showModal({
				title: '提示',
				content: '是否上传本地数据?',
				success: function(res) {
					if (res.confirm) {
						var promiseInfo = util.UpdateFn(0);
						promiseInfo.then(function(data){
							_this.getAPIData();
							_this.setData({
								updataCount: 0
							});
						}).catch(function(){
				
						});
					} else if (res.cancel) {
						console.log('用户点击取消')
					}
				}
			})
		};
	}
原文地址:https://www.cnblogs.com/yancongyang/p/9468588.html