优化数据发送逻辑,确保使用原始数据对象,并增加 props.data 变化的日志记录
Some checks failed
/ build-and-deploy-to-vercel (push) Successful in 3m19s
/ lint-build-and-check (push) Successful in 4m46s
/ playwright (push) Failing after 6m22s
/ surge (push) Successful in 2m36s

This commit is contained in:
严浩
2025-04-09 18:17:00 +08:00
parent 318fa4ea33
commit 2290dc2edf
2 changed files with 16 additions and 3 deletions

View File

@ -42,7 +42,8 @@ function sendDataToIframe(payload: Array<[number, number]>) {
// 确保 iframe 存在、其 contentWindow 可访问且已发送初始化指令 // 确保 iframe 存在、其 contentWindow 可访问且已发送初始化指令
if (iframeRef.value?.contentWindow && isIframeInitialized.value) { if (iframeRef.value?.contentWindow && isIframeInitialized.value) {
console.log('Vue 组件:向 iframe 发送数据:', payload); console.log('Vue 组件:向 iframe 发送数据:', payload);
iframeRef.value.contentWindow.postMessage({ type: 'FEED_DATA', payload }, '*'); // 使用 toRaw 获取原始数据对象
iframeRef.value.contentWindow.postMessage({ type: 'FEED_DATA', payload: toRaw(payload) }, '*');
} else { } else {
console.warn('Vue 组件iframe 未初始化或数据无效,无法发送 FEED_DATA 消息。'); console.warn('Vue 组件iframe 未初始化或数据无效,无法发送 FEED_DATA 消息。');
} }
@ -52,6 +53,7 @@ function sendDataToIframe(payload: Array<[number, number]>) {
watch( watch(
() => props.data, () => props.data,
(newData) => { (newData) => {
console.log('Vue 组件props.data 发生变化:', newData);
// 确保新数据有效且 iframe 已初始化 // 确保新数据有效且 iframe 已初始化
if (newData && newData.length > 0 && isIframeInitialized.value) { if (newData && newData.length > 0 && isIframeInitialized.value) {
// 直接发送更新后的数据 // 直接发送更新后的数据

View File

@ -6,11 +6,22 @@ definePage({
}, },
}); });
const data: Array<[number, number]> = [ type ConstellationDiagramArr = Array<[number, number]>;
const data = ref<ConstellationDiagramArr>([
[0.20898877234451796, 0.8329353515647436], [0.20898877234451796, 0.8329353515647436],
[-0.6589349632101078, 0.5886313023998213], [-0.6589349632101078, 0.5886313023998213],
[-0.5525702944049637, -0.7953057951401711], [-0.5525702944049637, -0.7953057951401711],
]; ]);
setTimeout(() => {
// 测试数据更新
data.value.push(
[0.20898877234451796, 0.8329353515647436],
[-0.6589349632101078, 0.5886313023998213],
[-0.5525702944049637, -0.7953057951401711],
);
}, 1000);
</script> </script>
<template> <template>