小编Ewa*_*ald的帖子

Electron - IPC - 在窗口之间发送数据

在主要过程中,我创建了一个名为的窗口mainWindow.在按钮上单击,我创建一个新的browserWindow被调用notesWindow.

我想要做的就是从发送数据notesWindowmainWindow

我所做的是使用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);
});
Run Code Online (Sandbox Code Playgroud)

noteWindow.js

const ipcRenderer = require('electron').ipcRenderer;
ipcRenderer.send('notes', "new note");
Run Code Online (Sandbox Code Playgroud)

mainWindow.js

const ipcRenderer = require("electron").ipcRenderer;
ipcRenderer.on('notes2', function(event, data) {
    // this function never gets called
    console.log(data);
});
Run Code Online (Sandbox Code Playgroud)

谁能解释我做错了什么?提前致谢!

ipc electron

9
推荐指数
1
解决办法
6837
查看次数

标签 统计

electron ×1

ipc ×1