javascript - react input file
问题描述
1 在我的页面中有一个隐藏的input type 类型的file元素,该元素通过ref属性可以获取到,取名为this.inputFile 2 页面头部右边有一个按钮,点击该按钮,触发该this,fileInput.click()3 但是结果却无法弹出文件选择框,真是的,这是什么问题啊,逻辑没问题啊 尴尬
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
问题解答
回答1:贴具体代码啊,这样好难脑补
相关文章:
1. nosql - mongodb 多组数据不固定字段查询问题 [百度党请绕道]2. 如何解决docker宿主机无法访问容器中的服务?3. javascript - 关于微信扫一扫的技术问题4. javascript - 跨域读取网站接口获取数据遭遇堵截5. 微信小程序支持跳转到外部链接网页吗6. HTML5不支持frameset一般怎么解决?7. 无法转换为java.lang.Throwable8. css3 - border-bottom 的长度可否超过盒子的宽度呢?实现如下图效果。(我的书下面的线)9. redis - 究竟是选择微信小程序自带的统计工具还是自己开发一个数据统计的代码?10. javascript - vue-cli项目中,获取微信access_token时遇到的跨域问题
![nosql - mongodb 多组数据不固定字段查询问题 [百度党请绕道]](http://www.haobala.com/attached/image/4.jpg)