mounted () {
history.pushState(null, null, document.URL);
window.addEventListener('popstate', this.disableBrowserBack);
},
destroyed () {
window.removeEventListener("popstate", this.disableBrowserBack, false);
}
methods
disableBrowserBack() {
history.pushState(null, null, document.URL);
this.$confirm('此操作将退出此页面未保存内容, 是否继续退出?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.$message({
type: 'success',
message: '成功退出!'
});
this.$router.go(-2);
}).catch(() => {
this.$message({
type: 'info',
message: '已取消'
});
});
}