【问题标题】:How do I load the index.html file on electron?如何在电子上加载 index.html 文件?
【发布时间】:2020-01-17 10:29:11
【问题描述】:

我正在使用电子和 Angular 创建一个应用程序。

目前要加载我的 index.html 文件,我的代码如下所示。

exports.window = function window() {

  this.createWindow = (theBrowserWindow) => {
    // Create the browser window.
    let win = new theBrowserWindow({
      width: 900,
      height: 600,
      webPreferences: {
        nodeIntegration: true
      },
      resizable:false
    });

    // and load the index.html of the app.
    win.loadFile(`file://${__dirname}/dist/index.html`)

    // Chrome Dev Tools
    win.webContents.openDevTools()  
  };
}

特别是

 win.loadFile(`file://${__dirname}/dist/index.html`)

但是,当我运行代码时,我不断收到错误消息。

Not allowed to load local resource:

我不确定如何为电子应用加载 index.html 文件。正确的语法是什么。

我尝试了“index.html”和“./index.html”,但似乎找不到解决方案。

任何关于放置什么的帮助将不胜感激

【问题讨论】:

标签: javascript html electron load


【解决方案1】:

我不确定你的项目结构,但是在我的 Electron 应用程序中加载窗口时,我在加载 html 页面时有以下内容:

mainWindow.loadFile(path.join(__dirname, 'index.html'));

在我目前的情况下,index.html 与正在执行窗口创建的 js 文件位于同一目录中。

【讨论】:

    猜你喜欢
    • 2023-02-05
    • 1970-01-01
    • 2017-12-09
    • 2017-10-30
    • 1970-01-01
    • 2021-06-06
    • 1970-01-01
    • 2020-01-09
    • 1970-01-01
    相关资源
    最近更新 更多