1.mounted中调用方法
mounted(){
this.browserBackBtn();
}
2.methods中监听返回按钮
browserBackBtn(){
this.pushHistory();
if (window.history &&window.history.pushState) {
window.addEventListener("popstate",this.callback,false);
}
},
callback(){
if(this.btnFlag ==true){
this.showAlert =true //显示弹框
this.alertMessage ='是否确认退出'
}else {
window.removeEventListener("popstate",this.callback,false)
this.goto(-1);
}
},
backConfirm(n){
let _this=this;
window.removeEventListener("popstate",_this.callback,false)
this.goto(n)
},
//提交二次确认按钮sure_checked和replace_checked是封装的弹窗组件中的确定和取消按钮
sure_checked(e){
this.backConfirm(-1)
},
//提交二次取消按钮
replace_checked(e){
if(e =='replace'){
this.showAlert =''
}
this.browserBackBtn();
},
网友评论