Node.js 将一些数据从前端窗口发送到电子浏览器窗口

Node.js 将一些数据从前端窗口发送到电子浏览器窗口,node.js,electron,Node.js,Electron,我想把一个物体从前端窗口送到电子的一端。 我试过这个: html: const ipcRender = require('electron').ipcRenderer; ipcRender.send('test', { test: null}); 节点: mainWindow.webContents.on('test', (event, data) => { console.log(true); console.log(data); }); 在控制台里什么也没看到。有什么不对劲

我想把一个物体从前端窗口送到电子的一端。 我试过这个:

html:

const ipcRender = require('electron').ipcRenderer;
ipcRender.send('test', { test: null});
节点:

mainWindow.webContents.on('test', (event, data) => {
  console.log(true);
  console.log(data);
});
在控制台里什么也没看到。有什么不对劲?
谢谢

我找到了解决方案,但如果不正确,请予以评论。 因此,不是在节点中使用“mainWindo.webContents”,而是必须使用从electron导入的“ipcMain”:

const { ipcMain } = require('electron');

ipcMain.on('test', (event, data) => {
  console.log(data);
});  

这似乎是一条路要走,API文档中的解释将与您的方法一致!