<input type="file" name="sendfile" id="sendfile" v-show='false' accept="image/png,image/gif,image/jpeg" @change='upload' multiple>
如上,一个支持多图片上传的input,怎么用filereader本地读取出每个图片的dataurl?这个upload该怎么写?
循环读取啊
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) } } })
循环读取啊