【发布时间】:2018-10-04 23:26:25
【问题描述】:
我正在使用一个名为 dropzone 的插件,它使图像呈现给用户的方式非常接近。
所以我已经这样做了
<Dropzone
onDrop={this.handleDropChange}}>
<p>
Try dropping some files here, or click to select files to upload.
</p>
</Dropzone>
@observable files = [];
@action
handleDropChange = (files) => {
files.forEach(file => {
this.loadFile(file);
});
}
@action
loadFile(file){
const reader = new FileReader();
reader.addEventListener('load',() => {
runInAction(() => {
this.files.push({file: file, preview: reader.result, uploaded: false})
window.URL.revokeObjectURL(reader.result);
});
},false);
// reader.readAsDataURL(file.fileObject);
}
<img src={this.props.preview} />
问题是当我拖入 500 张图像时,它们需要一段时间才能在屏幕上呈现。我认为 reactjs 很难,因为它本质上是重新渲染 500 次,因为每个“文件读取器加载”都会导致一个新项目被放入 files 数组。
是否可以批量处理或先完成所有加载然后重新渲染?
【问题讨论】:
标签: javascript reactjs file dropzone