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. mysql - AttributeError: ’module’ object has no attribute ’MatchType’2. python - from ..xxxx import xxxx到底是什么意思呢?3. 求大神幫我看看是哪里寫錯了 感謝細心解答4. npm鏡像站全新上線5. javascript - 圖片能在網站顯示,但控制臺仍舊報錯403 (Forbidden)6. 網頁爬蟲 - python爬蟲翻頁問題,請問各位大神我這段代碼怎樣翻頁,還有價格要登陸后才能看到,應該怎么解決7. php自學從哪里開始?8. MySQL客戶端吃掉了SQL注解?9. phpstady在win10上運行10. 數據庫 - MySQL 單表500W+數據,查詢超時,如何優化呢?
