update main concepts

This commit is contained in:
张磊 2019-01-21 16:30:20 +08:00
parent bac6602d82
commit 290199efef
2 changed files with 48 additions and 0 deletions

View File

@ -266,6 +266,30 @@ render(<my-first-element></my-first-element>, 'body')
在元素上添加 `ref={e => { this.anyNameYouWant = e }}` ,然后你就可以 JS 代码里使用 `this.anyNameYouWant` 访问该元素。
你也可以使用 `createRef` 来得到更高的性能:
```js
import { define, WeElement, createRef } from 'omi'
define('my-first-element', class extends WeElement {
onClick = (evt) => {
console.log(this.myRef.current) //h1
}
myRef = createRef()
render(props) {
return (
<div>
<h1 ref={this.myRef} onClick={this.onClick}>Hello, world!</h1>
</div>
)
}
})
render(<my-first-element></my-first-element>, 'body')
```
### extractClass
```js

View File

@ -283,6 +283,30 @@ render(<my-first-element></my-first-element>, 'body')
Add `ref={e => { this.anyNameYouWant = e }}` to attrs of the element, then you can get it by `this.anyNameYouWant`.
You can also use `createRef`:
```js
import { define, WeElement, createRef } from 'omi'
define('my-first-element', class extends WeElement {
onClick = (evt) => {
console.log(this.myRef.current) //h1
}
myRef = createRef()
render(props) {
return (
<div>
<h1 ref={this.myRef} onClick={this.onClick}>Hello, world!</h1>
</div>
)
}
})
render(<my-first-element></my-first-element>, 'body')
```
### extractClass
```js