html hyperapp web组件
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html hyperapp web组件相关的知识,希望对你有一定的参考价值。
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=2">
<meta name="apple-mobile-web-app-capable" content="yes">
<style>body{margin:0;padding:0;}</style>
<script type="module">
document.addEventListener('touchmove',e=>e.preventDefault(),{passive:false})
import { h, app } from 'https://unpkg.com/hyperapp?module'
const state = {
count: 0,
}
const actions = {
increment: value => state => ({ count: state.count + value }),
decrement: value => state => ({ count: state.count - value }),
getState: () => state => state,
}
const view = (element) => (state, actions) =>
h('div', {},
h('style', {}, '*{touch-action:manipulation;}'),
h('h1', output(element), state.count),
h('button', decrement(actions), '-'),
h('button', increment(actions), '+'),
)
const updateEvent = new CustomEvent('update')
const output = (element) => ({
onupdate: () => element.dispatchEvent(updateEvent)
})
const increment = ({increment}) => ({
onclick: () => increment(1),
})
const decrement = ({decrement}) => ({
onclick: () => decrement(1),
})
customElements.define('hyper-counter', class extends HTMLElement {
connectedCallback() {
this.attachShadow({mode:'open'})
this.actions = app(state, actions, view(this), this.shadowRoot)
this.actions.increment(+this.dataset.initCount || 0)
}
})
app(null, null, () =>
h('div', {},
h('hyper-counter'),
h('hyper-counter', {'data-init-count':100}),
h('hyper-counter', {
onupdate: e => console.log(e.target.actions.getState().count)
}),
)
, document.body)
</script>
以上是关于html hyperapp web组件的主要内容,如果未能解决你的问题,请参考以下文章
30Seconds|React,Vue,Angular,Hyperapp 等 JavaScript UI 库或框架的目的是什么?
html 类を使用してHyperappを书いてみたref:https://qiita.com/tom-u/items/5566fecf51fc30fff007
[Hyperapp] Interact with the State Object through Hyperapp Action functions
在 HTML 5 Web 组件中使用 font awesome
我们可以在常规的非 Blazor HTML 页面中将 Blazor 组件用作 Web 组件吗?
具有远程 HTML 导入的 Polymer/Web 组件未呈现