# 认识BrowserWindow
在Electron中,我们借助它内置的BrowserWindow
方法来实现窗口的开启
const { app, BrowserWindow } = require('electron')
app.on('ready', () => {
let mainWindow = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true,
contextIsolation: false,
}
})
mainWindow.loadFile('index.html')
let secondWindow = new BrowserWindow({
width: 400,
height: 300,
webPreferences: {
nodeIntegration: true
},
parent: mainWindow
})
secondWindow.loadFile('second.html')
})
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
在main.js
中,app
监听ready
状态,开启一个新的窗口,加载index.html
文件,这里还开启了第二个窗口,它是主窗口的子窗口,根据parent
属性指定,nodeIntegration
属性指定在js文件中可以使用node
环境提供的API,不过在最新的20版本中,还需要把contextIsolation
选项置为false
才可以使用。