angular - 电子在预标签内加载html
问题描述
我最近创建了一个电子/角度应用程序,它在内部运行以下内容main.ts
:
win.loadURL(url.format({
pathname: path.join(__dirname, 'dist/index.html'),
protocol: 'file:',
slashes: true
}));
当电子应用程序加载时,以下显示
不知何故,html 正在加载到 html 内的<pre>
标签内。我已经检查__dirname/dist
并且该文件夹包含所有正确的文件(即 index.html、main.js 等)。有没有人见过与电子类似的东西?如果是这样,关于发生了什么的任何线索?
解决方案
虽然不是很明显,但我解决了我的问题——我的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
}
});
推荐阅读
- php - Builder 如何用于实例化多个不同的实例?
- r - 使用 R 生成列中选择行的平均值
- image-processing - 如何将 RGB 或 HEX 颜色代码分组为更大的颜色组?
- c# - OpenFile 对话框保持资源打开
- typescript - 为度量 CDK 创建数学表达式
- python - 有没有办法在使用谷歌云功能时在 /tmp 中创建一个文件夹?
- docker - 集群在不同机器上运行的 vernemq docker 容器
- xamarin.forms - 推送/弹出页面时使用屏幕阅读器读取当前页面标题
- java - Spring Boot 2.2 多模块项目自动配置 JPA 失败
- google-apps-script - 无法从电子表格中的列中获取 URL(图像 URL 保存在列中)并使用 Google App Script 中的 urlfetchapp 创建 PDF