const createWindow = () => {
// Create the browser window.
const mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true, //教程只有此项,无下方两个参数设置,如需支持node内方法需设置此三项
contextIsolation: false,
enableRemoteModule: true
}
});
// and load the index.html of the app.
mainWindow.loadFile(path.join(__dirname, 'index.html')).then(r => {
console.log(r)
});
// Open the DevTools.
mainWindow.webContents.openDevTools();
};
在看教程中发现只有
nodeIntegration参数开启,electron12以上都需要配置contextIsolationandenableRemoteModule