1 There is a hidden input type file element in my page. This element can be obtained through the ref attribute and is named this.inputFile
2 There is a button on the right side of the page header. Click the button , trigger this, fileInput.click()
3 but the result is that the file selection box cannot pop up. Really, what is the problem? The logic is okay and embarrassing
class FileManage extends Component{
constructor(props){
super(props);
this.onHandleBack = this.onHandleBack.bind(this);
this.showOperationSheet = this.showOperationSheet.bind(this);
}
onHandleBack(){
this.props.history.goBack();
}
showOperationSheet(){
console.log('点击上传');
if(this.fileInput){
console.log('进入判断');
//很神奇,必须有这行代码,才能调用图片选择,我也很无奈啊。
console.log(this.fileInput.click());
this.fileInput.click()
}
};
render(){
return (
<p>
<p onClick={this.showOperationSheet}>按钮</p>
<p style={{display:"none"}}>
<form action="" encType="multipart/form-data" method='POST' onSubmit={this._onSubmit}>
<input type="file" ref={(input)=>{this.fileInput = input}} onChange={this._onChange}/>
</form>
</p>
</p>
)
}
}
export default FileManage
Post the specific code, it’s so hard to figure it out