第一步,在main.js中加上如下代码
//禁止后退功能
window.history.pushState(null, null, window.location.href);
window.addEventListener('popstate', function () {
window.history.forward(-1);
window.history.pushState(null, null, window.location.href);
});
第二步,在App.vue中加上如下代码
updated(){
// 在每个页面加载完成时执行以下代码
window.history.pushState(null, null, window.location.href);
},
注意:我 VUE 的版本是 “vue”: “^2.6.11”,