項目需要監聽瀏覽器的返回事件,然后我寫了以后發現這個頁面需要點擊兩次返回才能回去,請教這是什么原因,代碼是vue的。methods:{ //點擊返回時執行的方法
backTo(){
}
},
mounted () { if (window.history && window.history.pushState) {
history.pushState(null, null, document.URL) window.addEventListener('popstate', this.backto)
}
},
destroyed () {
window.removeEventListener('popstate', this.backto)
}代碼如上,點擊返回時能執行backto,但是要點兩次才能跳過去
監聽瀏覽器返回事件導致需要按兩次返回才行
慕尼黑5688855
2018-11-19 16:30:02
