【问题标题】:Electron loading html inside pre tag电子在预标签内加载html
【发布时间】:2023-03-27 02:40:01
【问题描述】:

我最近创建了一个电子/角度应用程序,它在 main.ts 中运行以下内容:

win.loadURL(url.format({
  pathname: path.join(__dirname, 'dist/index.html'),
  protocol: 'file:',
  slashes: true
}));

当electron app加载时,如下显示 不知何故,html 在 html 内的 <pre> 标记内加载。 我检查了__dirname/dist,该文件夹包含所有正确的文件(即 index.html、main.js 等)。有没有人见过与电子类似的东西?如果是这样,有什么线索可以说明发生了什么吗?

【问题讨论】:

    标签: angular electron


    【解决方案1】:

    虽然不是很明显,但我解决了我的问题 - 我的 win 对象发出警告,因为我使用的是服务人员,因此没有正确加载 html。

    解决方案:使用nodeIntegrationInWorker: true 属性。添加后,一切都像魔术一样工作。

      // Create the browser window.
      win = new BrowserWindow({
        x: 0,
        y: 0,
        width: size.width,
        height: size.height,
        webPreferences: {
          nodeIntegration: true,
          nodeIntegrationInWorker: true
        }
      });
    

    【讨论】:

    • 很好地找到了自己的答案:),如果您没有其他问题,您可以接受自己的答案吗? (点击投票按钮下方的勾号)
    • 哦,我不知道,对不起
    猜你喜欢
    • 1970-01-01
    • 2019-02-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多