Browse Source

监听浏览器返回

master
453530270@qq.com 2 years ago
parent
commit
a2a62fb9c2
  1. 5
      pages/login/components/main.vue
  2. 35
      pages/login/index.vue

5
pages/login/components/main.vue

@ -108,6 +108,8 @@
console.log('main created') console.log('main created')
}, },
methods: { methods: {
// //
@ -244,7 +246,8 @@
this.$navTo("pages/findpass/findpass") this.$navTo("pages/findpass/findpass")
}, },
} },
} }
</script> </script>

35
pages/login/index.vue

@ -32,6 +32,14 @@
} }
}, },
//
activated() {
if(window.history && window.history.pushState){
history.pushState(null, null, document.URL);
window.addEventListener('popstate', this.goBack, false);
}
},
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
*/ */
@ -65,6 +73,27 @@
// }) // })
}, },
//
goBack(){
// url
let history = store.state.urlHistory;
console.log(history,"history");
//
// if(history.length > 1) {
// // 1url
// router.push(history[history.length - 3]);
// } else {
// //
// router.push('/');
// }
// // 退popstate
// window.history.pushState('forward', null, '');
// window.history.forward(1);
// this.$router.replace({path: '/'});
},
// //
onGetUserInfoSuccess({ oauth, code, userInfo }) { onGetUserInfoSuccess({ oauth, code, userInfo }) {
// //
@ -78,8 +107,12 @@
// //
this.isMpWeixinAuth = false this.isMpWeixinAuth = false
// //
this.isParty = true // this.isParty = true
} }
},
//
deactivated() {
window.removeEventListener('popstate', this.goBack, false);
} }
} }
</script> </script>

Loading…
Cancel
Save