原生JS 监听物理返回键
1.在此使用的Vue写的,
mounted() {
//监听物理返回键
if (window.history && window.history.pushState) {
history.pushState(null, null, document.URL);
window.addEventListener('popstate', this.fun, false);//false阻止默认事件
}
},
methods: {
/**
* 监听物理返回键执行的方法
* */
fun(){
console.log("监听到了")
},
}