hello from main不打印
main.js代码:
const { app,BrowserWindow,ipcMain } = require('electron')
app.on('ready',()=>{
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences:{
nodeIntegration:true //使用node API
}
})
mainWindow.loadFile('index.html')
ipcMain.on('message',(event,arg)=>{
console.log(arg)
// event.sender.send('reply','hello from main')
mainWindow.send('reply','hello from main')
})
})
renderer.js代码:
const { ipcRenderer } = require('electron')
window.addEventListener('DOMContebtLoaded', ()=>{
ipcRenderer.send('message','hello from renderer')
ipcRenderer.on('reply',(event,arg)=>{
document.getElementById('message').innerHTML = arg;
})
})
index.html代码:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
</head>
<body>
<h1>Hello World!</h1>
<p id="message"></p>
<script>
require('./renderer.js')
</script>
</body>
</html>