const { ipcRenderer } = require("electron");
window.addEventListener("DOMContentLoaded", () => {
ipcRenderer.send("message", "hello from renderer");
});
// Modules to control application life and create native browser window
const { app, BrowserWindow, ipcMain } = require("electron");
app.on("ready", () => {
const mainwindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
//在应用中 可以使用 nodeJs 的API
nodeIntegration: true
}
});
mainwindow.loadFile("index.html");
ipcMain.on("message", (event, arg) => {
console.log(arg);
});
});
加这个试试