vue.js - Vue - 每次上传的进度条
问题描述
我当前的进度条被所有文件共享,因此进度条来回跳跃。如何分隔每个上传文件的进度条?
submitFiles() {
for( let i = 0; i < this.files.length; i++ ) {
if(this.files[i].id) {
continue;
}
let formData = new FormData();
formData.append('file', this.files[i]);
axios.post('/files/upload-file', formData, { headers: { 'Content-Type': 'multipart/form-data' },
onUploadProgress: function( progressEvent ) {
this.uploadPercentage = parseInt( Math.round( ( progressEvent.loaded / progressEvent.total ) * 100 ))
}.bind(this)
})
.then(function(data) {
this.files[i].id = data['data']['id'];
this.files.splice(i, 1, this.files[i]);
console.log('success');
}.bind(this))
.catch(function(data) {
console.log('error');
});
}
}
编辑:
我尝试了这种方法,并且在console.log
. 现在唯一的问题是如何percentage
在进度条中存储 的值。
const myUploadProgress = (myFileId) => (progress) => {
let percentage = Math.floor((progress.loaded * 100) / progress.total)
console.log(myFileId)
console.log(percentage)
}
for( let i = 0; i < this.files.length; i++ ) {
var config = {
onUploadProgress: myUploadProgress(this.files[i])
}
let formData = new FormData();
formData.append('file', this.files[i].name);
axios.post('/files/upload-file', formData, config, { headers: { 'Content-Type': 'multipart/form-data' },
模板:
<v-progress-linear max="100" :value="??"></v-progress-linear>
解决方案
推荐阅读
- node.js - 如何获得满足 mongodb 中字段所有条件的用户?
- javafx - 如何使 TextFieldTableCell 以模型属性为条件?
- c - c 创建两个新列表但得到错误的结果
- python - Python:代码突然不起作用 - “'NoneType' 对象没有属性 'lower'
- macos - 使用 LLVM MCJIT 时图像基集在哪里?
- automation - Ansible 'no_log' 用于调试输出中的特定值,而不是整个模块
- angular-material - angular 11 将静态文本显示为动态值
- python - 转换 ReadyAPI xpath 以在 Python 3 中使用
- r - 如何绘制许多没有锐边的概率密度函数(pdf)?
- powershell - 设置一个 SSIS 包包参数并使用新的 Param 值执行它