直接上代碼
mounted() {
if (window.history && window.history.pushState) {
history.pushState(null, null, document.URL);
window.addEventListener('popstate', this.fun, false); //false阻止默認事件 this.fun是指返回按建實際要執(zhí)行的方法
}
}
destroyed(){ // 銷毀時取消監(jiān)聽
window.removeEventListener('popstate', this.fun, false);//false阻止默認事件
},