weixin_慕少2558414
2020-02-04 16:25
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>
DOMContebtLoaded打错了,是DOMContentLoaded
Electron开发本地音乐播放器
4411 学习 · 53 问题
相似问题