Skip to content

Instantly share code, notes, and snippets.

@lichspace
Last active November 29, 2018 08:38
Show Gist options
  • Select an option

  • Save lichspace/fe6170d892d17ac2ac354c9bb1661b5e to your computer and use it in GitHub Desktop.

Select an option

Save lichspace/fe6170d892d17ac2ac354c9bb1661b5e to your computer and use it in GitHub Desktop.
react upload preview
handleChange(e){
console.log('file',e.target.files)
let files = [...e.target.files]
let that = this
let fileList = []
files.map((v,n)=>{
let reader = new FileReader(e);
reader.onload = function () {
let url = event.target.result
fileList.push({
originFile:v,
url:url||''
})
if(fileList.length===files.length){
that.setState({
fileList
})
}
}
reader.readAsDataURL(v);
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment