我开始尝试it -html和it-element,尝试使用它,现在我遇到了一个问题,我不知道如何在网上发布这样的代码。从来没有在在线平台上使用过Node-js包,只使用了其中的一些代码。通常我会构建普通的php/html模板,但我想试试这个。
在本地构建一些可以工作的测试用例。但我到处用谷歌搜索,想知道如何将这种代码发布到互联网上。我正在使用一个共享主机,有很多选项,比如SSH,但我不知道该怎么做才能让它工作,它不能像在我的服务器上运行npm install那么简单,对吧?
发布于 2019-09-09 07:08:40
关于web组件和at html及其朋友的新世界最好的事情是,我们实际上不需要npm,我们不需要编译,也不需要任何构建步骤。
现在,我们可以使用es-module直接从CDN加载内容,比如unpkg或jsdelivr
看看haunted's github readme上的演示--这就是你所需要的!
<!doctype html>
<html lang="en">
<my-counter></my-counter>
<script type="module">
import { html } from 'https://unpkg.com/lit-html/lit-html.js';
import { component, useState } from 'https://unpkg.com/haunted/haunted.js';
function Counter() {
const [count, setCount] = useState(0);
return html`
<div id="count">${count}</div>
<button type="button" @click=${() => setCount(count + 1)}>Increment</button>
`;
}
customElements.define('my-counter', component(Counter));
</script>check it out running live on this codepen example
?Chase
https://stackoverflow.com/questions/57716346
复制相似问题