先描述一下我遇到的问题:是一个.catch捕捉错误,点击确定返回上一页的问题其中用到了计时器然后,问题就来了,点击返回之后,计时器停止不了,哭泣showCourses() { getCommondityList( this.page, this.pageSize, changeSchoolRegionId, this.industryId ).then(res => { this.pageTotal = res.data.pageTotal; this.courseList = res.data.list; }).catch(err => { this.countNumber++; if (this.countNumber >= 3) { wx.showModal({ title: '提示', content: '网络异常,请稍后重试', showCancel: false, success(res) { if (res.confirm) { wx.navigateBack({ delta: 1 }); 开通血压监测小程序电话:4006-838-530 } } }) 开通定制T恤小程序电话:4006-838-530 } else { setTimeout(() => { this.showCourses(); }, 1000); } }); }
然后我想到了生命周期,onUnload停不下来的原因是因为计时器的问题,然后我在页面返回之后,清除了计时器的时间先赋值this.timer = setTimeout(() 开通来伊份券小程序电话:4006-838-530=> { this.showCourses(); }, 1000);
然后在onUnload() { clearTimeout(this.timer); }
也就是页面跳转,销毁本页面内容的时候,清除计时器,然后就可以了,哭泣微信小程序