update readme

This commit is contained in:
张磊 2018-10-31 17:39:18 +08:00
parent 746d24cd32
commit 277fadfc19
2 changed files with 50 additions and 0 deletions

View File

@ -208,6 +208,31 @@ define('my-counter', class extends WeElement {
render(<my-counter />, 'body')
```
你也可以定义成纯函数的形式:
```js
import { define, render } from 'omi'
define('my-counter', function() {
const [count, setCount] = this.use({
data: 0,
effect: function() {
document.title = `The num is ${this.data}.`
}
})
return (
<div>
<button onClick={() => setCount(count - 1)}>-</button>
<span>{count}</span>
<button onClick={() => setCount(count + 1)}>+</button>
</div>
)
})
render(<my-counter />, 'body')
```
## 快速入门
### 安装

View File

@ -206,6 +206,31 @@ define('my-counter', class extends WeElement {
render(<my-counter />, 'body')
```
You can also be defined as a form of pure functions:
```js
import { define, render } from 'omi'
define('my-counter', function() {
const [count, setCount] = this.use({
data: 0,
effect: function() {
document.title = `The num is ${this.data}.`
}
})
return (
<div>
<button onClick={() => setCount(count - 1)}>-</button>
<span>{count}</span>
<button onClick={() => setCount(count + 1)}>+</button>
</div>
)
})
render(<my-counter />, 'body')
```
## Getting Started
### Install