html5 - FileReader怎样一次读取多个文件?
问题描述
<input type='file' name='sendfile' v-show=’false’ accept='image/png,image/gif,image/jpeg' @change=’upload’ multiple>
如上,一个支持多图片上传的input,怎么用filereader本地读取出每个图片的dataurl?这个upload该怎么写?
问题解答
回答1:循环读取啊
new Vue({ el: ’app’, methods: { async upload () { const files = event.target.files const uploadList = [] console.log(files) const readFileAsync = file => new Promise(resolve => {const reader = new FileReader()reader.onload = evt => resolve(evt.target.result)reader.readAsDataURL(file) }) for (let i = 0; i < files.length; i++) {uploadList.push(await readFileAsync(files[i])) } event.target.value = null console.log(uploadList) } }})
相关文章:
1. javascript - 读js权威指南“作为值得函数”产生了疑惑,求释疑2. Python获取HTTP请求的状态码(200,404等)3. 前端需要设置 token的吗?4. python3.x - python中的虚拟环境怎样设置一直处于激活状态5. android - 使用listview加载不同item,数据填充错误。6. boostrap怎么在移动端不显示sidebar?7. python - from ..xxxx import xxxx到底是什么意思呢?8. python中merge后文件莫名变得非常大9. Python处理Dict生成json10. angular.js - angular js 报错 [$injector:modulerr] 模块注入错误