优化数据发送逻辑,确保使用原始数据对象,并增加 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 可访问且已发送初始化指令
if (iframeRef.value?.contentWindow && isIframeInitialized.value) {
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 {
console.warn('Vue 组件iframe 未初始化或数据无效,无法发送 FEED_DATA 消息。');
}
@ -52,6 +53,7 @@ function sendDataToIframe(payload: Array<[number, number]>) {
watch(
() => props.data,
(newData) => {
console.log('Vue 组件props.data 发生变化:', newData);
// 确保新数据有效且 iframe 已初始化
if (newData && newData.length > 0 && isIframeInitialized.value) {
// 直接发送更新后的数据