chore: init use demo
This commit is contained in:
parent
2f03508899
commit
e91efb3a68
|
@ -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')
|
|
@ -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)
|
Loading…
Reference in New Issue