This commit is contained in:
zhangsir
2024-05-28 18:32:58 +08:00
parent 108c639f1a
commit 0c565e52ab

View File

@@ -27,29 +27,23 @@ import portalFooter from "@/components/PortalFooter.vue";
if(params){
this.url=this.url+'?'+params;
}
window.addEventListener('hashchange', this.handleHashChange);
window.addEventListener('popstate', this.handlePopState);
window.addEventListener('message', this.handleMessageFromChild);
},
beforeDestroy() {
window.removeEventListener('hashchange', this.handleHashChange);
window.removeEventListener('popstate', this.handlePopState);
},
window.removeEventListener('message', this.handleMessageFromChild);
},
methods:{
handleHashChange() {
this.navigate();
},
handlePopState() {
this.navigate();
},
navigate() {
const navigatePath = new URLSearchParams(window.location.search).get('navigate');
if (navigatePath) {
// 清除查询参数
window.history.replaceState({}, '', location.pathname);
// 导航
this.$refs.iframe.src = navigatePath;
}
},
handleMessageFromChild(event) {
if (event.origin !== process.env.VUE_APP_BOE_MOBILE_URL) return;
if (event.data && event.data.type === 'navigate') {
this.navigate(event.data.path);
}
},
navigate(path) {
this.$router.push({
path:path
})
},
}
}
</script>