在文件上传过程中,onUploadprogress控制文件上传到服务器的时间,而服务器接收到文件并处理文件仍需要一定时间,所以在编写进度条时,应该注意有两个时间,文件上传时间和接口返回时间
const config = {
onUploadProgress: (progress) => {
// 格式化成百分数
let rate= Math.floor(progress.loaded/progress.total*100)'
if(rate<100){
this.progress = rate
}
}
}
axios.post(url,data,config).then(
this.progress = 100
)