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. docker images顯示的鏡像過多,狗眼被亮瞎了,怎么辦?2. Matlab和Python編程相似嗎,有兩種都學過的人可以說說嗎3. 請教各位大佬,瀏覽器點 提交實例為什么沒有反應4. javascript - avalon使用:duplex設置select默認option的bug5. javascript - Web微信聊天輸入框解決方案6. docker - 如何修改運行中容器的配置7. javascript - 音頻加載問題8. 網頁爬蟲 - 用Python3的requests庫模擬登陸Bilibili總是提示驗證碼錯誤怎么辦?9. javascript - 移動端textarea不能上下滑動,該怎么解決?10. css - 對于類選擇器使用的問題
