gpt4 book ai didi

javascript - 如何在 Electron 上加载index.html文件?

转载 作者:行者123 更新时间:2023-12-03 12:42:05 24 4
gpt4 key购买 nike

我正在用 Electron 和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:

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

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

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

最佳答案

我不确定您的项目结构,但是在加载窗口时,在我的Electron应用程序中,加载html页面时,我有以下内容:
mainWindow.loadFile(path.join(__dirname, 'index.html'));
目前,就我而言, index.html 与执行窗口创建的js文件位于同一目录中。

关于javascript - 如何在 Electron 上加载index.html文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59785545/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com