Electron Remode 模块的使用
1 创建 demo2.html 文件
2 创建 demo2.js 文件
const btn=this.document.querySelector('#btn')
const { BrowserWindow } = require('@electron/remote')
window.οnlοad=function(){
btn.οnclick=()=>{
newwin=new BrowserWindow({
width:800,
height:800
})
newwin.loadFile('yellow.html')
newwin.on('closed',()=>{
newwin=null
})
}
}
注意 const { BrowserWindow } = require('@electron/remote') 的使用,查看是否有remote模块是否存在
如果不存在,安装 npm i -D @electron/remote
3 修改主进程
注意添加的
enableRemoteModule: true
require('@electron/remote/main').initialize() //添加语句
require('@electron/remote/main').enable(mainWindow.webContents) //添加语句
4 添加yellow.html
5 运行 electron .