mirror of
https://codeup.aliyun.com/67762337eccfc218f6110e0e/vue/learning-system-portal.git
synced 2025-12-17 06:46:43 +08:00
测试
This commit is contained in:
@@ -27,29 +27,27 @@ import portalFooter from "@/components/PortalFooter.vue";
|
|||||||
if(params){
|
if(params){
|
||||||
this.url=this.url+'?'+params;
|
this.url=this.url+'?'+params;
|
||||||
}
|
}
|
||||||
window.addEventListener('hashchange', this.handleHashChange);
|
window.addEventListener('message', this.handleMessageFromChild);
|
||||||
window.addEventListener('popstate', this.handlePopState);
|
|
||||||
},
|
},
|
||||||
beforeDestroy() {
|
beforeDestroy() {
|
||||||
window.removeEventListener('hashchange', this.handleHashChange);
|
// 移除事件监听器
|
||||||
window.removeEventListener('popstate', this.handlePopState);
|
window.removeEventListener('message', this.handleMessageFromChild);
|
||||||
},
|
},
|
||||||
methods:{
|
methods:{
|
||||||
handleHashChange() {
|
handleMessageFromChild(event) {
|
||||||
this.navigate();
|
console.log('我进来了')
|
||||||
},
|
if (event.origin !== this.url) return; // 验证来源以防跨站脚本攻击
|
||||||
handlePopState() {
|
if (event.data && event.data.type === 'navigate') {
|
||||||
this.navigate();
|
this.navigate(event.data.path);
|
||||||
},
|
|
||||||
navigate() {
|
|
||||||
const navigatePath = new URLSearchParams(window.location.search).get('navigate');
|
|
||||||
if (navigatePath) {
|
|
||||||
// 清除查询参数
|
|
||||||
window.history.replaceState({}, '', location.pathname);
|
|
||||||
// 导航
|
|
||||||
this.$refs.iframe.src = navigatePath;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
navigate(path) {
|
||||||
|
// 清除查询参数
|
||||||
|
// 这里假设iframe加载的是子项目,可以通过改变iframe的src属性来导航
|
||||||
|
this.$router.push({
|
||||||
|
path:path
|
||||||
|
})
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user