From 19aca6ddc5844c893ab2f67e411669707a7b4a18 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A8=9C?= Date: Wed, 23 Apr 2025 14:18:26 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E5=A4=84=E7=90=86=E5=88=87=E6=8D=A2?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E6=97=B6=E8=BD=AE=E8=AF=A2=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.vue | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/App.vue b/src/App.vue index 8211c621..575a47f3 100644 --- a/src/App.vue +++ b/src/App.vue @@ -3,13 +3,35 @@ import { qiankunWindow } from 'vite-plugin-qiankun/dist/helper'; import '@vue-flow/core/dist/style.css'; import '@vue-flow/core/dist/theme-default.css'; import DialogueView from 'src/views/dialogue/dialogueView.vue'; +import { watch } from 'vue'; +import { useRouter } from 'vue-router'; +const router = useRouter(); + +// 监听路由变化,控制iframe内容的活动状态 +watch( + () => router.currentRoute.value.path, + (newPath) => { + const iframe = document.getElementById('my-iframe'); + const isWitchaindRoute = newPath === '/witchainD'; + if (!iframe) { + console.warn('未找到iframe元素'); + return; + } + if (!iframe.contentWindow) { + console.warn('iframe.contentWindow不可用'); + return; + } + const message = { StopActive: !isWitchaindRoute }; + // 向iframe发送消息,控制其活动状态 StopActive为false表示激活,为true表示停止 + let target = `${window.location.origin}/witchaind`; + iframe.contentWindow.postMessage(message, target); + }, + { immediate: true } // 初始化时也执行 +); -- Gitee