【问题标题】:reactjs formik file uploadreactjs formik文件上传
【发布时间】:2021-06-12 18:04:19
【问题描述】:

我想在 reactjs 中上传图片我正在使用 Formik 关注 https://codesandbox.io/s/lkkjpr5r7?file=/index.js:1808-1812

我的代码是:

               <Field
                className="attribute_input"
                name={this.props.fieldname}
                type="file"
                placeholder={
                    this.props.title
                }
                onChange={this.handleChange}
                   
                />

handlechange 有以下实现:

handleChange(event) {
        const reader = new FileReader();
        reader.onload = () => {
            if (reader.readyState === 2) {
                this.setState({file: reader.result})
            }
        } 
        reader.readAsDataURL(event.target.files[0]);
        console.log(this.props.fieldname);
        this.props.sfv("image1", event.currentTarget.files[0]);
    }

面临错误:

未能在“HTMLInputElement”上设置“value”属性:此输入 element 接受一个文件名,该文件名只能以编程方式设置为 空字符串。

【问题讨论】:

    标签: reactjs formik


    【解决方案1】:

    问题是

            <input
            className="attribute_input"
            name={this.props.fieldname}
            type="file"
            onChange={this.handleChange}
            />
    

    【讨论】:

      猜你喜欢
      • 2019-10-02
      • 1970-01-01
      • 2022-11-30
      • 1970-01-01
      • 2016-08-01
      • 2020-10-13
      • 1970-01-01
      • 2020-08-03
      • 1970-01-01
      相关资源
      最近更新 更多