在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML/ Ref引用傳遞是哪個input

Ref引用傳遞是哪個input

class CustomTextInput extends React.Component {
  constructor(props) {
    super(props);
    this.focus = this.focus.bind(this);
  }

  focus() {
    // 通過使用原生API,顯式地聚焦text輸入框
    this.textInput.focus();
  }

  render() {
    // 在實例中通過使用`ref`回調(diào)函數(shù)來存儲text輸入框的DOM元素引用(例如:this.textInput)
    return (
      <div>
        <input
          type="text"
          ref={(input) => { this.textInput = input; }} />
        <input
          type="button"
          value="Focus the text input"
          onClick={this.focus}
        />

      </div>
    );
  }
}
class AutoFocusTextInput extends React.Component {
  componentDidMount() {
    this.textInput.focus();
  }

  render() {
    return (
      <CustomTextInput
        ref={(input) => { this.textInput = input; }} />
    );
  }
}

下面這個在自定義組件上的ref,按理說參數(shù)input是裝載的組件實例。
但是CustomTextInput里有兩個input標(biāo)簽。這個到底是傳的哪個呢?求問

回答
編輯回答
伐木累

傳遞的是CustomTextInput這個組件

2018年2月23日 07:05