javascript - HTML 导入在 Electron 应用程序中不起作用

标签 javascript html electron web-component

我正在尝试使用 Electron 构建桌面应用程序。
我在导入 HTML 模板时遇到问题。
代码

<link rel="import" href="fileLocation/file.html">
文件.html
<template>
  <div>Template html content </div>
</template>
//script in index.html file
<script>
   const links = document.querySelectorAll('link[rel="import"]')
   Array.prototype.forEach.call(links, (link) => {
      let template = link.import.querySelector('template')
      //error: cannot read property "querySelectorAll" of undefined
      //I tried to console.log(link)
      //it gives output: <link rel="import" href="fileLocation/file.html">
      //but in electron demo app it is giving actual template.
   })

</script>
//running below code in my index.html to test html import compatibility
console.log(
    "Native HTML Imports?", 'import' in document.createElement('link'),
    "Native Custom Elements v0?", 'registerElement' in document,
    "Native Shadow DOM v0?", 'createShadowRoot' in document.createElement('div'));

//output: Native HTML Imports? false Native Custom Elements v0? false Native Shadow DOM v0? false

//running the same code in Electron API demo app (example app given on electron github repo)

console.log(
    "Native HTML Imports?", 'import' in document.createElement('link'),
    "Native Custom Elements v0?", 'registerElement' in document,
    "Native Shadow DOM v0?", 'createShadowRoot' in document.createElement('div'));

//output: Native HTML Imports? true Native Custom Elements v0? true Native Shadow DOM v0? true

请告诉我如何配置我的应用程序以使我的结果与 Electron 演示应用程序匹配。

最佳答案

我有同样的问题,似乎与新版本的 Electron (10.1.5)有关。
恢复到版本 7.2.4 对我有用

关于javascript - HTML 导入在 Electron 应用程序中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64837131/

相关文章:

javascript - Handlebars : More than one model inside template

javascript - 当用户按下 CTRL + S 时如何捕获?

javascript - 如何使 Electron 浏览器全屏大小?

node.js - 在 Electron 和 Webpack 中使用 node require

javascript - 将动态字符串绑定(bind)到 Electron JS 函数

javascript - 字符串拆分并获取第一次和最后一次出现

javascript - 我的 div 在不应该流血的时候流血

javascript - 我如何将数据存储在可从任何地方访问的 nextjs 中

html - 改变 body 不是 HTML/CSS 标准吗?

javascript - 在没有javascript的情况下使背景div与内容大小相同