代码
监听返回
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("点击了浏览器的返回按钮");
sessionStorage.clear();
window.history.back(); history.pushState(null, null, document.URL);
},
}
因为这个页面有跳转其他页面的路由,所以在组件的路由钩子里也清了缓存
beforeRouteLeave (to, from , next) {
sessionStorage.clear();
next()
},
禁用返回
mounted () {if (window.history &&window.history.pushState) {//向历史记录中插入了当前页
history.pushState(null, null, document.URL);
window.addEventListener('po