我只是尝试在 Windows 10 的桌面上测试 Electron 环境以使用 JavaScript 进行编程。
所以我有一个应用程序:
const electron=require("electron");
const app=electron.app;
const BrowserWindow=electron.BrowserWindow;
var mainWindow=null;
app.on("ready",function(){
mainWindow=new BrowserWindow({height:600,width:800});
mainWindow.loadURL("file://"+__dirname+"index.html");
});
index.html 是:
<html>
<head>
<title> MyIndex.html </title>
</head>
<body>
Hello World from Electron!<br>
</body>
</html>
package.json 是:
{
"name":"Electron-Test",
"version":"0.1.0",
"main":"./main.js",
"scripts":{"start":"electron ."}
}
如果我运行
electron .
或 npm start
应用程序似乎已启动,但没有打开浏览器窗口。在控制台上我必须按 Ctrl-C
停止应用程序。有谁知道问题出在哪里?
最佳答案
尝试再添加一个/
文件后:
您还缺少 /
之前 index.html
app.on("ready",function(){
mainWindow=new BrowserWindow({height:600,width:800});
mainWindow.loadURL("file:///"+__dirname+"/index.html");
});
我在这个视频中看到了,3:32 https://www.youtube.com/watch?v=i0AkgNv4U4E
关于electron - Electron 中的BrowserWindow无法打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43170517/