我试图在我的Electron 应用程序中将数据从Main.js发送到Renderer.js,但一旦它进入preload.js,它就会在一个空对象中转换.
在main.js中:
win.once('ready-to-show', () => {
win.webContents.send('setVideoSources', "test");
})
在prelaod.js中:
contextBridge.exposeInMainWorld('videoEvent', {
setVideoSources: (callback) => ipcRenderer.on('setVideoSources', (sources) => {
console.log(sources)
callback(sources);
}),
});
在renderer.js中
window.videoEvent.setVideoSources((sources) => {
console.log(sources)
});
这两个console.log
都显示一个空对象,我找不到为什么可以检索我的数据.(这里是"test"
,但当我try 将"真实数据"作为对象发送时,它显然是相同的).
如果有人有主意,让我知道!