首页 > 解决方案 > 如何将 lit-html 添加到现有项目中?

问题描述

我知道我可以lit-html使用<script type="module">say 中的标签导入index.html,但我无法访问htmlrender从单独的 JS 脚本(例如index.js)。这目前可能吗?

标签: javascriptlit-html

解决方案


很抱歉回答了一个老问题,但文档可能自 2018 年以来已更新。现在他们提供了有关如何执行此操作的说明。

使用 npm 安装 lit-html

npm install lit-html

然后像这样导入到你的 JS 文件中

import {html, render} from './node_modules/lit-html/lit-html.js';

html然后在需要的地方打电话render()https://lit-html.polymer-project.org/guide/getting-started#rendering-a-template)。


推荐阅读