Javascript 将React app函数分配给窗口变量
我有两个React应用程序版本驻留在同一页面上。一个是较新的应用程序(React 15),另一个是(React 16)。现在,它们通过全局变量相互传递数据。我想知道是否有一种方法可以通过一个全局变量将react 15应用程序中的函数调用到react 16应用程序中,该全局变量在安装时分配给旧应用程序中的函数 以下是我所拥有的: 反应15Javascript 将React app函数分配给窗口变量,javascript,reactjs,Javascript,Reactjs,我有两个React应用程序版本驻留在同一页面上。一个是较新的应用程序(React 15),另一个是(React 16)。现在,它们通过全局变量相互传递数据。我想知道是否有一种方法可以通过一个全局变量将react 15应用程序中的函数调用到react 16应用程序中,该全局变量在安装时分配给旧应用程序中的函数 以下是我所拥有的: 反应15 ... componentDidMount() { console.log('[componentDidUnmount]') window.p
...
componentDidMount() {
console.log('[componentDidUnmount]')
window.playFunction = this.restoreAllTimelines;
window.pauseFunction = this.pauseAllTimelines;
console.log(window.playFunction + " " + window.pauseFunction)
window.mainContainer = {
addStateValidator: this.addStateValidator,
};
this.props.start();
}
...
反应16
getScreenshotHandler = () => {
// These 2 lines communicate with content_script.js that's from the extension
var data = { type: "FROM_PAGE", text: "Screenshot Request" };
// window.postMessage(data, "*");
window.parent.postMessage(data, "*");
window.pauseFunction();
this.notify(true, "Screenshot Taken. Nice!")
if (this.state.pauseOnShot) {
triggerPlay();
}
}
componentWillUnmount() {
window.playFunction();
if (this.props.pauseOnShot) {
triggerPlay();
}
}
index.html
...
<script>
window.r15r16URLPipe=null;
window.playFunction=null;
window.pauseFunction=null;
<script/>
<div id="root"></div> //React 15
<div id="screenshot"></div> // React 16
...
。。。
window.r15r16URLPipe=null;
window.playFunction=null;
window.pauseFunction=null;
//反应15
//反应16
...
如有任何意见,将不胜感激。谢谢