问题遇到的现象和发生背景
想要点击两次退出应用,超过一秒的返回两次不退出,为什么第二次取的计数是累加后的值而不是重设的0
问题相关代码,请勿粘贴截图
data() {
return {
backButtonPress: 0,
}
},
onBackPress(options) {
console.log(this.backButtonPress);
this.backButtonPress++;
console.log(this.backButtonPress);
if (this.backButtonPress > 1) {
plus.runtime.quit();
} else {
plus.nativeUI.toast('再按一次退出应用');
}
setTimeout(function() {
this.backButtonPress = 0;
console.log(this.backButtonPress);
}, 1000);
return true;
},
运行结果及报错内容
10:35:07.809 [Number] 0 at pages/index/index.vue:102
10:35:07.829 [Number] 1 at pages/index/index.vue:104
10:35:08.814 [Number] 0 at pages/index/index.vue:112
10:35:11.730 [Number] 1 at pages/index/index.vue:102
10:35:11.750 [Number] 2 at pages/index/index.vue:104