chore: init use demo

This commit is contained in:
dntzhang 2019-12-20 16:40:49 +08:00
parent 2f03508899
commit e91efb3a68
5 changed files with 32 additions and 32 deletions

View File

@ -1,32 +0,0 @@
import { render, WeElement, define, observe } from '../../src/omi'
define('my-counter', @observe
class extends WeElement {
data = {
count: 1
}
css = `span{
color: red;
}`
sub = () => {
this.data.count--
}
add = () => {
this.data.count++
}
render() {
return (
<div>
<button onClick={this.sub}>-</button>
<span>{this.data.count}</span>
<button onClick={this.add}>+</button>
</div>
)
}
})
render(<my-counter />, 'body')

View File

@ -0,0 +1,32 @@
import { render, define, h } from '../../src/omi'
const store = {
data: {
count: 1
}
}
store.sub = () => {
store.data.count--
}
store.add = () => {
store.data.count++
}
define('my-counter', _ => (
<h.f>
<button onClick={_.store.sub}>-</button>
<span>{_.store.data.count}</span>
<button onClick={_.store.add}>+</button>
</h.f>
))
define('my-app', _ => (
<div>
<my-counter use={['count']} ></my-counter>
</div>
))
render(<my-app />, 'body', store)