// 禁用瀏覽器返回鍵 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);
則頁面提示一次后再點擊返回則依然會返回,如果添加以上代碼,多次點擊返回也可以