关于electron中入口文件main.js一些重要参数(持续更新maybe)

const {app, BrowserWindow} = require('electron')
const path = require('path')


let mainWindow
function createWindow () {
  console.log(123)
  mainWindow = new BrowserWindow({
    width: 900,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js'),
      nodeIntegration:true//设置此项以使用nodejs
    },
    frame:true
  })


  mainWindow.loadFile('main.html')
  
  mainWindow.on('closed', function () {
    
    mainWindow = null
  })
}


app.on('ready', createWindow)

app.on('window-all-closed', function () {
  if (process.platform !== 'darwin') app.quit()
})

app.on('activate', function () {
  if (mainWindow === null) createWindow()
})

  第一次发博:

      在函数createWindow中设置第一个渲染进程mainWindow里有一个webpreferences,里面的第一个参数暂不知道,也许后续会更新。第二个参数是如果当前进程所使用的的html文件需要用到nodejs模块则必须加这个参数,且设置为true,否则所有目标html文件中的nodejs语句都会失效

猜你喜欢

转载自www.cnblogs.com/zxh2459917510/p/11022922.html