popstate:返回事件
goPage(item) {
this.show = true
if (window.history && window.history.pushState) {
this.preventDefault = true;
// 往历史记录里面添加一条新的当前页面的url
history.pushState(null, null, document.URL);
}
},
hijack() {
// 给 popstate 绑定一个方法
window.addEventListener("popstate", this.backNative);
},
backNative(e) {
if (this.preventDefault) {
e.preventDefault();
this.show = false
//执行后清除preventDefault
this.preventDefault = false;
} else {
console.log("默认");
}
},
removeHijack() {
window.removeEventListener("popstate", this.backNative);
},