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. java - web項目中,用戶登陸信息存儲在session中好 還是cookie中好,取決于什么?2. angular.js - webpack build后的angularjs路由跳轉問題3. java - Activity中的成員變量被賦值之后,Activity被回收的時候內存才會被釋放嗎4. 為什么bindClass訪問不了的?5. 老師,flex-shrink: 1; 按視頻操作,不會自動縮放6. 數組按鍵值封裝!7. php由5.3升級到5.6后,登錄網站,返回的是php代碼,不是登錄界面,各位大神有知道的嗎?8. 請求一個數據返回內容為空或者錯誤如何再次請求幾次9. 使用list和each配合,的作業,輸出一行后,如何換行10. Discuz! Q 有人用過嗎?
