【发布时间】:2017-09-15 03:14:02
【问题描述】:
在主进程中,我创建了一个名为mainWindow 的窗口。单击按钮后,我创建了一个名为 notesWindow 的新 browserWindow。
我想做的是将数据从notesWindow发送到mainWindow
我所做的是使用IPC发送首先将数据从notesWindow发送到主进程,检索主进程上的数据,然后将数据发送到mainWindow,但是mainWindow无法接收到发件人事件。将数据发送到主进程可以正常工作,但从主进程到 browserWindow 似乎不起作用。
main.js
const ipcMain = require('electron').ipcMain;
ipcMain.on('notes', function(event, data) {
console.log(data) // this properly shows the data
event.sender.send('notes2', data);
});
noteWindow.js
const ipcRenderer = require('electron').ipcRenderer;
ipcRenderer.send('notes', "new note");
mainWindow.js
const ipcRenderer = require("electron").ipcRenderer;
ipcRenderer.on('notes2', function(event, data) {
// this function never gets called
console.log(data);
});
谁能解释我做错了什么?提前致谢!
【问题讨论】: