生命週期創建頁面添加 監聽
mounted() {
if (window.history && window.history.pushState) {
console.log('監聽');
history.pushState(null, null, document.URL);
window.addEventListener('popstate', this.backHome, false);
}
},
綁定監聽方法
methods:{
backHome() {
console.log('執行監聽');
this.qingkong();
this.searchValue = ""
// this.bodyClear();
this.$router.push('/' + this.activetype);
},
}
最後 頁面銷燬 移除監聽事件
destroyed() {
console.log('銷燬監聽');
window.removeEventListener('popstate', this.backHome, false);
},