简体   繁体   English

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

[英]HTML import is not working in Electron app

I'm trying to build desktop app using Electron. I'm having issue importing HTML template.我正在尝试使用 Electron 构建桌面应用程序。我在导入 HTML 模板时遇到问题。

Code代码

<link rel="import" href="fileLocation/file.html">

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

Please tell me how can I configure my app so that my result matches with Electron demo app.请告诉我如何配置我的应用程序,以便我的结果与 Electron 演示应用程序匹配。

I had same issue and seem like it's related to new version of electron (10.1.5).我有同样的问题,似乎与 electron (10.1.5) 的新版本有关。

Revert back to version 7.2.4 works for me恢复到版本 7.2.4 对我有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM