电子快速启动应用程序不工作

Nul*_*ter 4 html javascript json angularjs electron

我是新手,electron并试图遵循不同的教程.目前我正在关注此链接以编写我的第一个电子应用程序

app的结构是这样的

your-app/
 ??? package.json
 ??? main.js
 ??? index.html
Run Code Online (Sandbox Code Playgroud)

格式package.json

 {
  "name"    : "your-app",
  "version" : "0.1.0",
  "main"    : "main.js"
}
Run Code Online (Sandbox Code Playgroud)

这是我的 main.js

'use strict';

const electron = require('electron');
const app = electron.app;  // Module to control application life.
const BrowserWindow = electron.BrowserWindow;  // Module to create native browser window.

// Keep a global reference of the window object, if you don't, the window will
// be closed automatically when the JavaScript object is garbage collected.
var mainWindow = null;

// Quit when all windows are closed.
app.on('window-all-closed', function() {
  // On OS X it is common for applications and their menu bar
  // to stay active until the user quits explicitly with Cmd + Q
  if (process.platform != 'darwin') {
    app.quit();
  }
});

// This method will be called when Electron has finished
// initialization and is ready to create browser windows.
app.on('ready', function() {
  // Create the browser window.
  mainWindow = new BrowserWindow({width: 800, height: 600});

  // and load the index.html of the app.
  mainWindow.loadURL('file://' + __dirname + '/index.html');

  // Open the DevTools.
  mainWindow.webContents.openDevTools();

  // Emitted when the window is closed.
  mainWindow.on('closed', function() {
    // Dereference the window object, usually you would store windows
    // in an array if your app supports multi windows, this is the time
    // when you should delete the corresponding element.
    mainWindow = null;
  });
});
Run Code Online (Sandbox Code Playgroud)

index.html是我想要展示的网页:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="UTF-8">
    <title>Hello World!</title>
  </head>
  <body>
    <h1>Hello World!</h1>
    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>.
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

现在,当我electron在我的应用程序的源目录中运行命令时,它显示了这一点

这个

而不是这个结果

代替

每次我将我拖到index.html第一张图像的空白区域以获得第二张图像的结果.

我不知道我做错了什么.请帮助我在这个简单的应用程序中错误的地方.任何形式的帮助将不胜感激.

Nul*_*ter 9

我必须设法electron index.html解决这个问题。

  • 网络上没有任何记录。我浪费了至少半天,感到非常沮丧。您节省了其余时间。谢谢! (2认同)

Ale*_*isi 5

您必须将package.json所在的目录作为参数传递给电子命令.因此,如果您从应用程序目录中执行电子,则必须编写

electron .
Run Code Online (Sandbox Code Playgroud)