我正在 React 中处理文件上传,将文件存储在 FileList 中并显示预览。图像似乎存储正确,但没有呈现并且alt文本不断显示。
this.props.file 包含这样的东西: file: "blob:http://localhost:3000/1d648245-4447-41a4-b11e-a5a7b385bb9b"
上传组件的代码如下:
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import './Upload.css';
import { setFile } from '../../actions/imagefile';
class Upload extends Component {
static propTypes = {
history: PropTypes.object,
setFile: PropTypes.func,
file: PropTypes.object,
}
handleChange = (event) => {
this.props.setFile({
file: URL.createObjectURL(event.target.files[0]),
});
}
render() {
return (
<div>
<input type="file" onChange={this.handleChange} />
<img src={this.props.file} alt="reviewed img" />
</div>
);
}
}
const mapStateToProps = (state) => ({
file: state.imageFile.file,
});
export default connect(mapStateToProps, {
setFile,
})(Upload);
芜湖不芜
相关分类