参考资料:

  https://ask.csdn.net/questions/767017

  https://www.cnblogs.com/best-fyx/p/11363506.html

我使用的是element-ui中的 Upload 上传 组件,最终效果

组件对应的 on-progress事件绑定的方法

handleProgressing(event, file, fileList) {
var per = (event.loaded * ) / event.total
var size = event.total / /
this.step = 2.77
this.timeSpan = per = per * 0.75
if (per > 72.1) {
if (!this.isTimer)
if (size > ) {
this.step = 1.43
this.timeSpan =
} if (size > ) {
this.step = 0.43
this.timeSpan =
} if (size > ) {
this.step = 0.33
this.timeSpan =
} if (size > ) {
this.step = 0.21
this.timeSpan =
} if (size > ) {
this.step = 0.17
this.timeSpan =
} if (size > ) {
this.step = 0.09
this.timeSpan =
}
if (size > ) {
this.step = 0.07
this.timeSpan =
} if (size > ) {
this.step = 0.06
this.timeSpan =
} if (size > ) {
this.step = 0.05
this.timeSpan =
} if (size > ) {
this.step = 0.03
this.timeSpan =
} //一定在这里定义timer变量,然后在定时器里面清除,不然不好用
var isTimer1 = setInterval(() => {
if (this.p >= ) this.step = 0.01
this.p = parseFloat(this.p) + this.step
if (this.p >= 99.97) this.p = 99.99
this.processStr = this.p.toFixed() + '%' console.log(this.processStr)
if ((this.processStr = '100%')) {
console.log('window')
window.clearInterval(isTimer1)
}
}, this.timeSpan)
// console.log(' this.isTimer')
// console.log(this.isTimer)
} else {
this.processStr = per.toFixed() + '%'
}
}

上传成功的方法:

    successlUpload() {
this.processStr = '100%' //设置这个标志位,定时器里面的清除逻辑就会执行
this.isTimer =
this.$refs.uploadFile.abort()
this.uploading = false
},

上传成功后把显示的字符串改为100%就可以了。

我这个写的原因是我的上传文件分两块。

过程: 1.vue上传文件到接口服务器(webapi)

    2.接口把文件上传到azure

所以我把上传进度显示改为模拟的了,按照文件的大小设置上传进度的step。

你们直接报错到服务器的话可以不使用我代码的这一块。

最新文章

  1. Linux计划任务.md
  2. 剑指Offer-【面试题05:从头到尾打印链表】
  3. 转:浅谈UNIX下Apache的MPM及httpd.conf配置文件中相关参数配置
  4. inotify +rsync进行实时同步
  5. poj1949Chores(建图或者dp)
  6. Android 手机卫士--自定义组合控件构件布局结构
  7. 关于UID和GID的创建、修改、删除;简要举例
  8. JQuery高性能优化
  9. 高通Android平台硬件调试之Camera篇
  10. 【JavaScript】javascript常用的东西
  11. swift创建对象use of undeclared type 自己的类
  12. 纯css 写三角形
  13. web前端之文件上传
  14. cocos2d-x学习资源汇总(持续更新。。。)
  15. 手机端 H5上传头像
  16. 在windows XP系统下编译和使用ffmpeg
  17. JavaScript对象入门指南
  18. Frame
  19. ret和retf
  20. Mysql(三)约束

热门文章

  1. PlayJava Day008
  2. .NET MVC后台获得VIEW对应的html
  3. 协议分析中的TCP/IP网络协议
  4. GBT22239-2019等保2.0三级要求
  5. 安卓开发笔记(三十三):Android仿写微信发现
  6. 【LeetCode】650. 只有两个键的键盘
  7. [转]JVM系列一:JVM内存组成及分配
  8. HBase安装学习
  9. Angular 学习笔记(一)
  10. zsh: command not found: 解决方法