Electron快速入门
2024-09-07 23:48:22
node -v
npm -v
安装node环境
my-electron-app/
├── package.json
├── main.js
└── index.html
为您的项目创建一个文件夹并安装 Electron:
mkdir my-electron-app && cd my-electron-app
npm init -y
npm i --save-dev electron
main.js代码:
const { app, BrowserWindow } = require('electron') function createWindow () {
const win = new BrowserWindow({
width: 800,
height: 600,
webPreferences: {
nodeIntegration: true
}
}) win.loadFile('index.html')
} app.whenReady().then(createWindow) app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
}) app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Hello World!</title>
<meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';" />
</head>
<body style="background: white;">
<h1>Hello World!</h1>
<p>
We are using node <script>document.write(process.versions.node)</script>,
Chrome <script>document.write(process.versions.chrome)</script>,
and Electron <script>document.write(process.versions.electron)</script>.
</p>
</body>
</html>
package.json
{
"name": "my-electron-app",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"start": "electron ."
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"electron": "^11.2.2"
}
}
启动:npm start 命令行
最新文章
- Struts2第一个入门案例
- 2.5 C#的数据类型
- 【LeetCode】#7 Reverse Integer
- Swift 值类型和引用类型
- 完全偶图K(3,3)与完全图K5是否存在平面表示
- 解除SQL对组件";Ad Hoc Distributed Queries";的";STATEMENT&#39;OpenRowset OpenDatasource";的访问
- 安装rkhunter
- mysql 操作日期函数【增加,减少时间】
- 私有pod简记
- [Apio2012]dispatching
- element 如何自定义主题
- 如何搭一个vue项目
- ftp 传输问题
- 使用React改版网站
- 使用JDBC+POI把Excel中的数据导出到MySQL
- 对称(DES/AES)与非对称(RSA/SSL/数字证书)加密介绍及实际应用
- Redis的强大之处
- flow类型检查
- mysql获取表列信息、主键信息
- Linux中read命令的用法—(6/30)