尝试使用lit-html
. 当我尝试添加示例组件时,我遇到了错误。
使用electron: ^5.0.6
尝试导入模块my-element.js
(大部分代码是示例代码,我只是想让它工作)
<head>
<!-- Polyfills only needed for Firefox and Edge. -->
<script src="https://unpkg.com/@webcomponents/webcomponentsjs@latest/webcomponents-loader.js"></script>
</head>
<body>
<!-- Works only on browsers that support Javascript modules like
Chrome, Safari, Firefox 60, Edge 17 -->
<script type="module" src="my-element.js"></script>
该模块my-element.js
包含以下内容:
import {LitElement, html, css} from 'lit-html';
class MyElement extends LitElement {
static get properties() {
return {
mood: {type: String}
}
}
static get styles() {
return css`.mood { color: green; }`;
}
render() {
return html`Web Components are <span class="mood">${this.mood}</span>!`;
}
}
customElements.define('my-element', MyElement);
页面加载时出现错误
Failed to load module script: The server responded with a non-JavaScript MIME type of "". Strict MIME type checking is enforced for module scripts per HTML spec.
我尝试了不同的导入方式,lit-html
但没有解决错误。
前任。import {LitElement, html, css} from '../../node_modules/lit-html/lit-html';
前任。import {LitElement, html, css} from '../../node_modules/lit-html/lit-html.js';