【问题标题】:Send some data from front end window to electron browser window从前端窗口发送一些数据到电子浏览器窗口
【发布时间】:2019-02-11 18:37:28
【问题描述】:

我想将一个对象从前端窗口发送到电子端。 我试过这个:

html:

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

节点:

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

并没有在控制台中看到任何内容。有什么问题? 谢谢!

【问题讨论】:

    标签: node.js electron


    【解决方案1】:

    我找到了解决方案,但如果不正确,请发表评论。 因此,不要在 Node 中使用“mainWindo.webContents”,而必须使用从电子导入的“ipcMain”:

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

    【讨论】:

    猜你喜欢
    • 2018-05-20
    • 2011-02-18
    • 2021-03-24
    • 1970-01-01
    • 2019-11-04
    • 2020-05-11
    • 1970-01-01
    • 1970-01-01
    • 2017-02-21
    相关资源
    最近更新 更多