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

  • 报废汽车残值收入
  • 小规模30万免税包括30万吗
  • 企业纳税证明是什么
  • 企业利息收入需要交哪些税
  • 增值税减免税申报明细表举例
  • 出口退税贷方余额是什么意思
  • 个税专项扣除如何申报
  • 实收资本增加的原因
  • 银行存款没有期初余额的总账怎么填
  • 固定资产折旧年限的最新规定2022
  • 低值易耗品怎么报废
  • 支付平台使用费怎么算
  • 预交增值税怎么入账
  • 税金总额是税金的意思吗
  • 解聘职工赔偿工资包括哪些
  • 装修改造增值税税率
  • 出口用的增值税税率
  • 房地产行业零税率发票
  • 上个月有留抵税这个月怎么结转税金
  • 增值税和消费税常用的公式
  • 总资产报酬率可以用净利润计算吗
  • 无形资产的入账价值包括宣传费吗
  • 生产车间消耗品管理表
  • 预提费用和应付利息一样吗
  • 销项增值税普通发票
  • 过期商品报损账务处理?
  • 超市开具预付卡发票不征税发票上税吗
  • 工资薪金支出账载金额小于实际发生额
  • 自行研发的专利权计入
  • iphone无法打开网页怎么办
  • uniapp异常处理
  • windows11怎么显示我的电脑
  • 支付公司保洁费未开发票
  • 混合销售怎么分别核算
  • php read
  • 借条丢了怎么办打电话给家长
  • linux子网掩码自动变成24
  • php表单的作用是什么
  • 最好用的无人品牌子
  • 伊兰简介
  • yii2框架优秀在哪里
  • 代订机票发票可以入账吗
  • h5页面跳转小程序不显示按钮
  • 采购折让分录
  • python编程自动化框架怎么搭建
  • vue新手教程
  • 软件公司股权
  • mongodb操作语句
  • 金蝶k3费用发票怎么生成凭证
  • 个人独资企业需要会计做账吗
  • 补缴上年度所得税的会计分录
  • 申报个税劳务报酬按20%扣
  • mysql导入导出sql文件
  • solaris 11.4
  • 简单易上手 固态硬盘SSD安装WIN7系统的3种办法
  • xp主题设置
  • mac修改用户名称
  • win8 开机
  • windows xp系
  • win8开始菜单在右边
  • Linux分区详解
  • win7电量
  • win8正版系统自带
  • 每日十条中医用药经验
  • django模块详解
  • android native opengl
  • linux,windows
  • linux开机启动进程
  • 你可能不知道的湖北
  • nodejs客户端程序开发
  • 深入理解中国式现代化
  • jquery 滑动显示
  • android学什么
  • 点击电子税务局里的税务数字账户不跳转怎么回事
  • 高速公路过路费一公里多少钱
  • 如何查询企业税务情况
  • 重庆地税电子税务局app
  • 总公司与分公司签订承包协议
  • 青岛个人所得税咨询电话是多少
  • 所有企业都要做应急预案吗
  • 免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

    鄂ICP备2023003026号

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

    友情链接: 武汉网站建设