生命周期创建页面添加 监听
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);
},