Browse Source

监听浏览器返回

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

7
pages/login/components/main.vue

@ -107,9 +107,11 @@
created() { created() {
console.log('main created') console.log('main created')
}, },
methods: {
methods: {
// //
radioChange(evt) { radioChange(evt) {
this.userType = evt.detail.value this.userType = evt.detail.value
@ -244,7 +246,8 @@
this.$navTo("pages/findpass/findpass") this.$navTo("pages/findpass/findpass")
}, },
} },
} }
</script> </script>

37
pages/login/index.vue

@ -31,6 +31,14 @@
partyData: {} partyData: {}
} }
}, },
//
activated() {
if(window.history && window.history.pushState){
history.pushState(null, null, document.URL);
window.addEventListener('popstate', this.goBack, false);
}
},
/** /**
* 生命周期函数--监听页面加载 * 生命周期函数--监听页面加载
@ -64,6 +72,27 @@
// console.log('setShowUserInfo complete') // console.log('setShowUserInfo complete')
// }) // })
}, },
//
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,9 +107,13 @@
// //
this.isMpWeixinAuth = false this.isMpWeixinAuth = false
// //
this.isParty = true // this.isParty = true
} }
} },
//
deactivated() {
window.removeEventListener('popstate', this.goBack, false);
}
} }
</script> </script>

Loading…
Cancel
Save