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. nignx - docker內nginx 80端口被占用2. docker網絡端口映射,沒有方便點的操作方法么?3. docker - 各位電腦上有多少個容器啊?容器一多,自己都搞混了,咋辦呢?4. docker綁定了nginx端口 外部訪問不到5. docker不顯示端口映射呢?6. angular.js - angular內容過長展開收起效果7. java - 為什么此私有靜態變量能被訪問呢?8. fragment - android webView 返回后怎么禁止重新渲染?9. php - mysql 模糊搜索問題10. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?
