跳到主内容

示例预览

在本节中,我们收集了一些新手通用的功能示例,可以让你快速实现需要的 Electron 应用。 每个例子都包含一个简单的、自成一体的示例应用程序。 运行这些示例的最简单方法是下载 Electron Fiddle

一旦安装了Fiddle,就可以按下 "Open in Fiddle"按钮,然后会在下面找到以下代码样本:

const { app, BrowserWindow } = require('electron')const path = require('path')
function createWindow () {  const win = new BrowserWindow({    width: 800,    height: 600,    webPreferences: {      preload: path.join(__dirname, 'preload.js')    }  })
  win.loadFile('index.html')}
app.whenReady().then(() => {  createWindow()
  app.on('activate', () => {    if (BrowserWindow.getAllWindows().length === 0) {      createWindow()    }  })})
app.on('window-all-closed', () => {  if (process.platform !== 'darwin') {    app.quit()  }})

Open in Fiddle

How to...?#

You can find the full list of "How to?" in the sidebar. If there is something that you would like to do that is not documented, please join our Discord server and let us know!