使用vue开发webApp,安卓手机自带回退键的问题解决 - 流浪_光头 - 博客园
内容
```js
mounted(){
if (window.history && window.history.pushState) {
history.pushState(null, null, document.URL);
window.addEventListener('popstate', this.fun, false);//false阻止默认事件
}
},
destroyed(){
window.removeEventListener('popstate', this.fun, false);//false阻止默认事件
},
methods:{
fun(){
console.log("监听到了");
}
}
```
```js
mounted(){
if (window.history && window.history.pushState) {
history.pushState(null, null, document.URL);
window.addEventListener('popstate', this.fun, false);//false阻止默认事件
}
},
destroyed(){
window.removeEventListener('popstate', this.fun, false);//false阻止默认事件
},
methods:{
fun(){
console.log("监听到了");
}
}
```