[英]Store an image in browser storage using input type 'file' - Reactjs
[英]select multiple images using <input type=“file” />, update the state to store the image URLs, dynamically add <img /> tags to display them in reactjs
this.state = {
imageURL: []
};
fileSelectHandler = (event) => {
this.setState({
imageURL: [???]
});
}
<input type="file" multiple onChange={fileSelectHandler} />
<img src={imageURL[0]} />
在這里,我需要根據所選圖像的數量動態添加多個img標簽。 請幫忙!
關於文件更改,您可以在此處嘗試示例代碼
fileSelectHandler = (e) => {
Array.from(e.target.files).forEach(file => {
const reader = new FileReader();
reader.onload = (e) => {
this.setState({
images: this.state.images.concat(e.target.result),
});
};
reader.readAsDataURL(file);
})
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.