简体   繁体   English

javascript,electron,ipc 没有给出错误或 output

[英]javascript, electron, ipc doesn't give error or output

I'm new to js and electron, i keep getting no outputs or errors when running this code.我是 js 和 electron 的新手,运行此代码时我一直没有收到任何输出或错误。 Any help would be appreciated.任何帮助,将不胜感激。

//Main.js
const ipcMain = require('electron').ipcMain;

ipcMain.on('x', function(event, arg) {
    console.log(arg);
});

// index.html
const { ipcRenderer } = require('electron').ipcRenderer;
ipc.send('x', "Hello");

输出

You should open the DevTools console in your main window;您应该在主 window 中打开 DevTools 控制台; there are most certainly error messages displayed there telling you what's going wrong in your renderer process.那里肯定会显示错误消息,告诉您渲染器过程中出了什么问题。

There are at least two issues in your code:您的代码中至少有两个问题:

1/ The line 1/ 线

const { ipcRenderer } = require('electron').ipcRenderer;

should be either:应该是:

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

or:或者:

const ipcRenderer = require('electron').ipcRenderer;

2/ Once correctly defined, use ipcRenderer , not ipc : 2/ 一旦正确定义,使用ipcRenderer ,而不是ipc

ipcRenderer.send('x', "Hello");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM