位置: IT常识 - 正文

el-upload实现上传文件并展示进度条(el-upload上传文件大小限制)

编辑:rootadmin
el-upload实现上传文件并展示进度条

推荐整理分享el-upload实现上传文件并展示进度条(el-upload上传文件大小限制),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:el-upload手动上传文件,el-upload上传文件大小限制,el-upload上传大文件,el-upload上传文件,el-upload上传文件,el-upload上传文件,el-upload上传文件,el-upload上传文件,内容如对您有帮助,希望把文章链接给更多的朋友!

el-upload实现上传文件并展示进度条(el-upload上传文件大小限制)

el-upload在实现文件上传时无法触发on-progress钩子,即使调用后端接口并成功的情况下都无法触发,可以通过如下配置来解决:

const config = { onUploadProgress: progressEvent => { if (progressEvent.lengthComputable) { this.uploadProgress = Math.round((progressEvent.loaded / progressEvent.total) * 100) console.log('progressEvent>>', progressEvent) console.log('uploadProgress>>', _this.uploadProgress) } } }

随后将config添加至调用后端接口,即可成功获取进度~

html:

前端-上传文件获取进度条: <el-upload v-show="!fileList.length" ref="fileUpload" class="upload-demo" style="display: inline-block;height: 32px;margin-left: 8px" action="#" :file-list="fileList" :http-request="uploadVersion" :on-change="handleChange" :on-success="handleSuccess" :on-progress="handleProgress" :on-error="handleError" :auto-upload="true" :show-file-list="false" > <!-- icon_upload.svg--> <el-button type="primary" style="height: 32px;display: flex;align-items: center"><svg-icon icon-class="icon_upload" style="margin-right: 8px" />上传文件</el-button> <!-- <el-input v-model="uploadForm.filename" placeholder="请选择">--> <!-- &lt;!&ndash; <template slot="append"><el-button&ndash;&gt;--> <!-- &lt;!&ndash; size="mini"&ndash;&gt;--> <!-- &lt;!&ndash; >&ndash;&gt;--> <!-- &lt;!&ndash; 上传文件&ndash;&gt;--> <!-- &lt;!&ndash; </el-button></template>&ndash;&gt;--> <!-- </el-input>--> </el-upload> <!-- <el-button size="small" @click="sendClick">上传</el-button>--> <div v-if="fileElProgress"> <div class="el-progress-div"> <div><div v-loading="true" style="display: inline-block;width: 24px; height: 16px; padding-right: 8px;" />{{ fileName }}</div> <span> <span style="display: inline-block;margin-right: 8px">{{ progressPercent }}%</span> <el-button type="text" @click="cancelUpload">取消</el-button> </span> </div> <el-progress :percentage="progressPercent" :text-inside="false" :color="customColors" :stroke-width="2" /> <!-- :stroke-width="16" status="scuccess"--> </div> <template v-if="!fileElProgress"> <div v-for="item in fileList" :key="item.name" class="fail-list"> <div class="list-item"> <span :style="{color:showFailTip?'#FF3D00':'#fff' }"> <svg-icon :icon-class="showFailTip? 'icon_error_file': 'icon_success_file'" /> {{ item.name }} </span> <span style="float: right;display: flex;align-items: center;"> <span style="color: #878D99;display: inline-block;margin-right: 16px">{{ showFailTip ? '失败':'成功' }}</span> <!-- <span>{{ '失败' }}</span>--> <el-button style="color: #00E3FF" type="text" size="small" @click="fileList = []">删除</el-button> <el-button v-show="showFailTip" style="color: #00E3FF" type="text" size="small" @click="sendClick">重新上传</el-button> </span> </div> </div> </template>

JS部分

data() { return { // 进度条 fileList: [], showFailTip: false, customColors: [ { color: 'rgba(223,228,237,0.10)', percentage: 0 }, { color: '#00adc9', percentage: 100 } ], fileElProgress: false, fileProgressText: '', progressPercent: 0, } methodss:{ uploadVersion(params) { const _this = this this.uploadForm.filename = params.file.name this.fileFormData = new FormData() this.fileFormData.append('file', params.file) this.fileFormData.append('md5File', params.file) this.fileName = params.file.name const config = { onUploadProgress: progressEvent => { if (progressEvent.lengthComputable) { _this.uploadProgress = Math.round((progressEvent.loaded / progressEvent.total) * 100) console.log('progressEvent>>', progressEvent) console.log('uploadProgress>>', _this.uploadProgress) this.fileElProgress = true if (this.progressPercent < 99) { this.progressPercent = _this.uploadProgress } else { this.fileProgressText = '正在上传' } } } } uploadFile(this.fileFormData, config).then(res => { if (res.data === 'success') { this.fileProgressText = '上传成功' } else { this.showFailTip = true } this.fileElProgress = false }) }, } },
本文链接地址:https://www.jiuchutong.com/zhishi/285147.html 转载请保留说明!

上一篇:格洛里亚附近的码头和糖面包山,巴西里约热内卢 (© f11photo/Getty Images)(格洛利亚酒店)

下一篇:如何在vue中实现文件预览功能(vue实战技巧)

  • 人力资源外包可以选择简易计税吗
  • 怎样在电子税务局查询已开发票
  • 小规模纳税人收入是含税还是不含税
  • 金税盘服务费全额抵扣是什么意思
  • 投标保证金保险怎么买
  • 长期股权投资是金融资产还是非金融资产
  • 公司团体体检的洽谈
  • 产品没货怎么给客户解释
  • 银行打出的明细清单怎么看不懂
  • 短期借款有哪些
  • 供用电合同主要有
  • 装订凭证要如何写
  • 购买东西进项税在借方还是贷方
  • 公司章程上的出资时间2050年
  • 哪些发票可以进账认证
  • 出口不退税怎么做账
  • 季度不超9万
  • 应收利息的核算范围
  • 小规模纳税人如何开专票
  • 按揭的车可以只买交强险吗
  • 小规模差旅费分录
  • 网页老是自己跳出来
  • 苹果mac电脑下刻字怎么弄
  • 贴现到期不获付款
  • 计提税金及附加怎么算
  • 付款后收到发票怎么写摘要
  • win10待机自动关机软件
  • 企业核定征收管理办法
  • 无线路由器限速怎么办
  • 融资租赁业务的特点
  • 杜鹃花的养殖方法和修剪
  • 若依框架是什么框架
  • yii2前后端分离
  • 尚融资本
  • 2022年 change detection遥感图像变化检测 论文附代码
  • 前端微信小程序支付功能怎么实现
  • mongodb用法
  • 帝国cms怎么加自己的名字
  • mongodb数据删除
  • 开具红字增值税普通发票
  • mysql误删数据
  • 个人劳务报酬的个税
  • 普通发票和增值税发票报销有什么区别?
  • 个税专项附加扣除什么意思
  • 买到库存货 退货
  • 工人晚上加班的说说心情
  • 自产产品对外捐赠确认收入吗
  • 银行利息收入怎么计算
  • 取得无形资产发生的相关费用
  • 政府给的专款专用的补贴需要交税吗
  • 新建厂房房产证办理流程
  • 已经计提的坏账收回了怎么做
  • 小规模纳税人开票限额是多少
  • 金税盘开完发票可以直接拔掉吗?
  • 购买新发票的时候要带旧发票去吗?
  • mysql动态sql语句赋值
  • 如何在卸载程序中隐藏已安装程序
  • linux系统密码设置
  • ubuntu怎么添加一个新用户
  • macbookair numbers
  • win7删除搜索历史记录
  • win8电脑定时关机怎么设置方法
  • 如何让xp系统崩溃
  • linux设置权限755
  • 升级win10系统后电脑变卡处理方法
  • win10虚拟机不能使用
  • win8无法更新到win10
  • js常用的设计模式
  • 彻底弄懂js中的this指向
  • android ui绘制
  • dos脚本 菜鸟教程
  • perl 教程
  • vue music
  • Android---41---Service简介
  • 咪咕游戏包括什么
  • jquery中有几种方法可以来设置和获取样式
  • 即征即退什么时候确认收入
  • 出口免税不退税主要适用于
  • 国税地税征管体制改革方案全文
  • 吉林省职称查询入口
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

    网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

    友情链接: 武汉网站建设