// 禁用浏览器返回键 history.pushState(null, null, document.URL); window.addEventListener('popstate', this.disableBrowserBack);
在mounted中添加以上代码,其中disableBrowserBack为方法,
在methods中定义方法
disableBrowserBack(){ alert("无法返回,请提交") history.pushState(null, null, document.URL); window.addEventListener('popstate', this.disableBrowserBack); }
如果在以上方法中不再加
history.pushState(null, null, document.URL);
window.addEventListener('popstate', this.disableBrowserBack);
则页面提示一次后再点击返回则依然会返回,如果添加以上代码,多次点击返回也可以