electron在创建新窗口后html报错
在mainjs创建新窗口
//调用 BrowserWindow打开新窗口 newWin =new BrowserWindow({ width: 800, height: 700, minWidth: 800, minHeight: 700 })
结果打印报错
vue:6 TypeError: window.require is not a function at wn.closeWin (wechat-window.html:35) at He (vue:6) at HTMLButtonElement.n (vue:6) at HTMLButtonElement.Yr.o._wrapper (vue:6)
//调用 BrowserWindow打开新窗口 newWin =new BrowserWindow({ width: 800, height: 700, minWidth: 800, minHeight: 700, //加上这段主进程和渲染进程通信 webPreferences: { contextIsolation: false, // 设置此项为false后,才可在渲染进程中使用electron api nodeIntegration: true } })
html文件
const { ipcRenderer } = window.require('electron'); ipcRenderer.send('window-close')