微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

htm

编程之家收集整理的这个编程导航主要介绍了htm编程之家,现在分享给大家,也给大家做个参考。

htm 介绍

htm 实际上将jsX风格的语法更进一步!htm适用于大多数Virtual DOM库 .

npm安装:

npm i htm

import htm from 'https://unpkg.com/htm?module'

const html = htm.bind(react.createElement);

// just want htm + preact in a single file? there's a highly-optimized version of that:

import { html,render } from 'https://unpkg.com/htm/preact/standalone.mjs'

例子:

<!DOCTYPE html>

<html lang="en">

<title>htm Demo</title>

<script type="module">

import { html,Component,render } from 'https://unpkg.com/htm/preact/standalone.mjs';

class App extends Component {

addTodo() {

const { todos = [] } = this.state;

this.setState({ todos: todos.concat(`Item ${todos.length}`) });

}

render({ page },{ todos = [] }) {

return html`

<div class="app">

<${Header} name="Todo's (${page})" />

<ul>

${todos.map(todo => html`

<li>${todo}</li>

`)}

</ul>

<button onClick=${() => this.addTodo()}>Add Todo</button>

<${Footer}>footer content here<//>

</div>

`;

}

}

const Header = ({ name }) => html`<h1>${name} List</h1>`

const Footer = props => html`<footer ...${props} />`

render(html`<${App} page="All" />`,document.body);

</script>

</html>

GitHub:https://github.com/developit/htm

网站描述:使用标准标记模板的 JSX 替代方案

htm

官方网站:

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。