原生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("監聽到了")
},
}