位置: 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实战技巧)

  • s5500交换机(s5570)(s5500交换机 web)

  • 小米平板5pro是什么屏幕(小米平板5pro是什么处理器)

  • oppo watch怎么用微信(oppowatch怎么用小天才)

  • 微信多久不用会被冻结(微信多久不用会被限制登录)

  • 小牛充电器为什么这么烫(小牛充电器为什么是三孔)

  • 一个手机可以注册几个快手号(一个手机可以注册几个qq号码)

  • 微信交电费最晚多久到账(微信交电费最晚到几点)

  • 毒虚假发货怎么处理(毒虚假发货会扣保证金吗)

  • 保存与另存为的区别(保存与另存为的区别和联系有哪些)

  • 怎么解除添加好友风险(怎么解除添加好友频繁)

  • win10电脑卡顿怎么解决(win10电脑变卡顿)

  • 苹果8plus采用什么屏幕(苹果8plus什么功能特性)

  • 苹果x美版三网是高通基带吗(苹果x美版三网和双网什么区别)

  • 微信验证回复最多几条(微信验证回复最多显示三条)

  • 苹果6sp支持2.4a快充吗(苹果6sp支持2.1A快充吗)

  • ipad可以扩大内存吗(ipad内存能扩大吗)

  • 京东换货原物返回是什么意思(京东换货原物返回可以再申请退货吗)

  • 手机信号e是什么意思(手机信号e是什么意思怎么办)

  • 联想笔记本end键在哪(联想笔记本键盘f1到f9功能怎么关闭)

  • 华为mate30怎么设置用机姿势提醒(华为mate30怎么设置动态壁纸)

  • vivox27为啥没有人脸识别(vivox27为啥没有视频美颜)

  • xr的siri在哪里

  • uhd是什么意思(相机uhd是什么意思)

  • iphone热点怎么踢人(苹果手机热点怎么踢人)

  • Windows 10如何使用人脉新建联系人(windows 10如何使用)

  • 帝国cms灵动标签里的序号如何实现(帝国cms灵动标签排除上一篇下一篇文章)

  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设 电脑维修 湖南楚通运网络