el => this.el = el
很抱歉
function(el) { this.el = el }
(
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions
)
ref
关键字,用于获取元素引用以供将来使用,如
focus
事件。我们有两种方法
裁判
.
方式1(使用ref字符串)
class MyComponent extends Component {
focusInput() {
this.refs.inputAge.focus();
}
render() {
return(
<input ref="inputAge" />
)
}
}
这样,所有的裁判
this.refs
.
方式2(使用箭头功能)
class MyComponent extends Component {
focusInput() {
this.inputAge.focus();
}
render() {
return(
<input ref={ref => this.inputAge = ref} />
)
}
}
通过这种方式,我们可以保持ref在任何我们想要的地方,因为我们通过函数控制它。