验证中...
Cordova + Vue 打包apk实现点击两次退出应用
Raw Copy
//注意在 deviceready 后使用,写在methods中(method())
//点击返回按键
onBackKeyDown() {
this.$toast("再点击一次退出应用");
document.removeEventListener("backbutton", this.onBackKeyDown, false); // 注销返回键
document.addEventListener("backbutton", this.exitApp, false); //绑定退出事件
setInterval(() => {
document.addEventListener("backbutton", this.onBackKeyDown, false);
document.removeEventListener("backbutton", this.exitApp, false);
}, 3000);
},
//关闭APP
exitApp() {
navigator.app.exitApp();
}
//生命周期钩子(created和beforeDestroy)
//启动事件
created() {
document.addEventListener("backbutton", this.onBackKeyDown, false);
this.refreshTask();
this.refreshNotice();
}
//销毁事件
beforeDestroy() {
document.removeEventListener("backbutton", this.onBackKeyDown, false); // 注销返回键
document.removeEventListener("backbutton", this.exitApp, false);
}
//如果页面使用了<keep-alive>标签,那么销毁事件的时机为页面离开之前。
beforeRouteLeave(to, from, next) {
document.removeEventListener("backbutton", this.onBackKeyDown, false); // 注销返回键
document.removeEventListener("backbutton", this.exitApp, false);
this.$indicator.close()
next()
}

Comment list( 0 )

Sign in for post a comment

Help Search

191139_cd20d5fd_5186603 191143_ebef6f8d_5186603