我先貼上代碼,然后說說我自己的理解,請高手幫我指正一下class AutoFocusInput extends Component { componentDidMount () { this.input.focus() } render () { return ( <input ref={(input) => this.input = input} /> ) }}ReactDOM.render( <AutoFocusInput />, document.getElementById('root'))<input ref={(input) => this.input = input} />這段代碼,我實在不理解this指代的是什么,是ref所在的input標簽?還是class AutoFocusInput這段代碼<input ref={(input) => this.input = input} />翻譯過來就是<input ref={function(input) ={return this.input = input} /> 就是讓this.input=input,這里的this就是指代的input標簽吧,假如我有很多個這種input標簽,this的含義就是指我當前選擇的這個input表現。不知道我以上的理解到底對不對,謝謝
React學習過程中遇到一句不理解的語法
守候你守候我
2019-03-20 09:07:41


