繁体   English   中英

为 lit-element 导入 JavaScript 在浏览器中出现 404 not found 错误

[英]JavaScript import for lit-element gives me 404 not found error in browser

我已经在 ASP.NET MVC 5 解决方案中通过 npm 安装了 lit-element。 我正在尝试创建一个起始标记,如https://lit-element.polymer-project.org/guide/start指南中所述。 在浏览器中,我在 chrome 中得到“GET http://localhost:64580/node_modules/lit-element/lit-element ”net::ERR_ABORTED 404(未找到)。

<head>
    <script src="~/Scripts/my-element.js" type="module"></script>
</head>
<body>
    <my-element></my-element>
</body>

我的元素.js

import { LitElement, html } from "../node_modules/lit-element/lit-element";

class MyElement extends LitElement {

    render() {
        return html`
      <!-- template content -->
      <p>A paragraph</p>
    `;
    }
}

customElements.define('my-element', MyElement);

修改import

import { LitElement, html } from "lit-element";

这可以解决这个问题
像这样导入

import {
  html,
  LitElement,
} from 'https://unpkg.com/@polymer/lit-element@latest/lit-element.js?module';

暂无
暂无

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

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