iview的Upload组件进度条的坑

iview的Upload组件进度条的坑
使⽤官⽅上传组件时,需要显⽰有进度条
这是官⽅代码
<template>
<div class="demo-upload-list" v-for="item in uploadList">
<template v-if="item.status === 'finished'">
<img :src="item.url">
<div class="demo-upload-list-cover">
<Icon type="ios-eye-outline" @click.native="handleView(item.name)"></Icon>
<Icon type="ios-trash-outline" @click.native="handleRemove(item)"></Icon>
</div>
</template>
<template v-else>
<Progress v-if="item.showProgress" :percent="item.percentage" hide-info></Progress>
</template>
</div>
<Upload ref="upload" :show-upload-list="false" :default-file-list="defaultList" :on-success="handleSuccess" :format="['jpg','jpeg','png']" :max-size="2048" :on-form    <div >
<Icon type="ios-camera" size="20"></Icon>
</div>
</Upload>
<Modal title="View Image" v-model="visible">
<img :src="'o5wwk8baw.qnssl/' + imgName + '/large'" v-if="visible" >
</Modal>
</template>
<script>
export default {
data () {
return {
defaultList: [
{
'name': 'a42bdcc1178e62b4694c830f028db5c0',
'url': 'o5wwk8baw.qnssl/a42bdcc1178e62b4694c830f028db5c0/avatar'
},
{
'name': 'bc7521e033abdd1e92222d733590f104',
云梦县教育局
'url': 'o5wwk8baw.qnssl/bc7521e033abdd1e92222d733590f104/avatar'
}
],
imgName: '',
visible: false,
uploadList: []
}
},
methods: {
handleView (name) {
this.imgName = name;
this.visible = true;
},
handleRemove (file) {
const fileList = this.$refs.upload.fileList;
this.$refs.upload.fileList.splice(fileList.indexOf(file), 1);
},
handleSuccess (res, file) {
file.url = 'o5wwk8baw.qnssl/7eb99afb9d5f317c912f08b5212fd69a/avatar';
file.name = '7eb99afb9d5f317c912f08b5212fd69a';
},
南京市人口与计划生育规定
handleFormatError (file) {
this.$Notice.warning({
title: 'The file format is incorrect',
desc: 'File format of ' + file.name + ' is incorrect, please select jpg or png.'
});
},
handleMaxSize (file) {
this.$Notice.warning({方玉婷
title: 'Exceeding file size limit',
desc: 'File  ' + file.name + ' is too large, no more than 2M.'      });
},
handleBeforeUpload () {
const check = this.uploadList.length < 5;
if (!check) {
this.$Notice.warning({
title: 'Up to five pictures can be uploaded.'
});
}
return check;
}
},
mounted () {
this.uploadList = this.$refs.upload.fileList;
}
}
</script>
<style>
.demo-upload-list {
display: inline-block;
width: 60px;
height: 60px;
text-align: center;
line-height: 60px;
border: 1px solid transparent;
border-radius: 4px;
overflow: hidden;
background: #fff;
position: relative;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2);
margin-right: 4px;
}
.demo-upload-list img {
width: 100%;
height: 100%;
}
.demo-upload-list-cover {
display: none;
position: absolute;
top: 0;
bottom: 0;
left: 0;
right: 0;
background: rgba(0, 0, 0, 0.6);
}
.demo-upload-list:hover .demo-upload-list-cover {
display: block;
}
.demo-upload-list-cover i {
color: #fff;
si69font-size: 20px;
cursor: pointer;
梅森素数margin: 0 2px;
}
</style>
使⽤后发现进度条压根没有??,什么⿁?
查看了其他朋友也⼜遇到这种情况,发现有解决⽅案,需要调⽤on-progress
handleProgress (event, file, fileList) {
progress = (event)=>{
// event.loaded  已经上传了⽂件⼤⼩
// al  上传⽂件总⼤⼩
let uploadPercent = ((event.loaded / al) * 100).toFixed(1) + '%'
console.log(uploadPercent)
}
}
打印出进度了,但我们需要进度条
handleProgress (event, file, fileList) {
console.log('上传中', event); // 继承了原⽣函数的 event 事件
代理之狐console.log('上传中 file', file); // 上传的⽂件
console.log('上传中 fileList', fileList); // 上传⽂件列表包含file
// uploadList 就是原⽂档中的那个渲染的 uplist 是个数组,所以要把filelist 赋值给他
//  this.uploadList = fileList  为什么不⽤这个呢,因为我在删除其中⼀个图⽚在添加时,发⽣bug,所以不⽤
this.uploadList.push(file)
// 调⽤监听上传进度的事件
progress = (event) => {
let uploadPercent = parseFloat(((event.loaded / al) * 100).toFixed(2)) // 保留两位⼩数,具体根据⾃⼰需求做更改
// ⼿动设置显⽰上传进度条以及上传百分⽐
file.showProgress = true
file.percentage = uploadPercent
}
}

本文发布于:2024-09-21 10:52:35,感谢您对本站的认可!

本文链接:https://www.17tex.com/xueshu/396809.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:上传   进度条   发现
留言与评论(共有 0 条评论)
   
验证码:
Copyright ©2019-2024 Comsenz Inc.Powered by © 易纺专利技术学习网 豫ICP备2022007602号 豫公网安备41160202000603 站长QQ:729038198 关于我们 投诉建议