mounted() {//监听物理返回键// 如果支持 popstate (一般移动端都支持)if (window.history && window.history.pushState) {// 往历史记录里面添加一条新的当前页面的urlhistory.pushState(null, null, document.URL);// 给 popstate 绑定一个方法 监听页面刷新window.addEventListener('popstate', this.goBack, false);//false阻止默认事件}},destroyed () { //退出页面时销毁监听事件,防止其他页面使用window.removeEventListener('popstate', this.goBack, false);//false阻止默认事件},methods: {goBack() {console.log("监听到了");//点击物理返回键要执行的操作}}
