能够通过ref调起<input type="file"/>的选择文件吗?

#1

能够通过ref调起的选择文件吗?

#2

得要有事件触发才行吧。

#3

ref可以但是不推荐,直接用onChange事件

#4

解决了

onChange(e) {
  let file = e.target.files[0];
}
aa() {
    this.inputRef.click();
  }

  render() {
    return (
      <div className="choose-image" onClick={this.aa.bind(this)}>
        <Icon type="plus" className="icon" />
        <input ref={ref => this.inputRef = ref} type="file" accept="image/*" onChange={this.onChange.bind(this)}/>
      </div>
    )
  }