reactjs formik文件上传
reactjs formik file upload
我想在 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]);
}
面临错误:
Failed to set the 'value' property on 'HTMLInputElement': This input
element accepts a filename, which may only be programmatically set to
the empty string.
问题是
<input
className="attribute_input"
name={this.props.fieldname}
type="file"
onChange={this.handleChange}
/>
我想在 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]);
}
面临错误:
Failed to set the 'value' property on 'HTMLInputElement': This input element accepts a filename, which may only be programmatically set to the empty string.
问题是 <input
className="attribute_input"
name={this.props.fieldname}
type="file"
onChange={this.handleChange}
/>