export let openedWindows = []
然后在App.js上导入模块:
import * as globalVars from './global';
然后在componentDidMount
方法中将其附加到窗口:
window.openedWindows = globalVars.openedWindows
当我打开一个新窗口时,我只是将窗口对象推送到数组:
handleAddWindow = (newWindow) => {
window.openedWindows.push(newWindow)
}
我可以从其他窗口/标签中关闭它或做任何我想做的事情:
handleCloseWindow = () => {
window.opener.openedWindows[index].close()
window.opener.openedWindows.splice(index,1)
}
希望对某人有所帮助:)