首先阻止浏览器返回的事件
mounted() {
if (window.history && window.history.pushState) {
// 向历史记录中插入了当前页
history.pushState(null, null, document.URL);
window.addEventListener('popstate', this.goBack, false);
}
},
destroyed() { //离开这个界面之后,删除事件
window.removeEventListener('popstate', this.goBack, false);
},
在写入自己的自定义行为
methods: {
goBack() {
console.log("触发返回");
// 在这里写自己的业务逻辑
// window.history.back();
// this.modelVisible = true;
},
},