我已经构建了React项目X(已经编译(,我还有其他React项目Y。所以我想在项目 Y 中与Iframe项目 X 一起使用。我创建了 React 组件,放置<iframe id="iframe" src="./templates/JobAction/index.html" />
它加载得很好,但是当我想将数据发送到Iframe时,iframe.contentWindow.postMessage(dataToSend, '*');
什么也没得到。我已经订阅了项目 Xwindow.addEventListener("message", (event) => {console.log(event,888);});
仍然什么都没有。
我已经解决了!只需将项目 X复制到带有webpacknew CopyWebpackPlugin
的输出文件夹中