效果展示

在这里插入图片描述

HTML

这里用的是element默认的上传地址action,代码如下

<div>
  <el-upload
    action="https://jsonplaceholder.typicode.com/posts/"
    list-type="picture"
    :show-file-list="false"
    :on-success='uploadSuccess'
    :on-progress='uploaded'
    >
    <div>上传</div>
  </el-upload>
  <div class="imgList" v-for="(item,index) in urlList" :key="index">
    <div class="box" v-if="item.uid == uid">
      <el-progress type="circle" :percentage="Math.round(item.percentage)"></el-progress>
    </div>
    <img v-if="item.percentage == 100" :src="item.url" alt="">
  </div>
</div>

data数据

data(){
  return {
    urlList:'',  //图片List
    uid:null,    //图片唯一的标识id
  };
},

methods方法

methods:{
  uploadSuccess(response, file, fileList){
    this.uid = 1 //随便一个值,上传成功时,进度条消失
  },
  uploaded(event, file, fileList){
    this.urlList = fileList
    this.uid = file.uid
  }
}

css样式

<style lang="scss" scoped>
  .imgList{
    width: 100px;
    height: 100px;
    border:1px dotted #ccc;
    position:relative;
    float: left;
    img{
      width: 100px;
      height: 100px;
    }
    .box{
      position:absolute;
      left:35px;
      top:25px;
    }
    /deep/ .el-progress-circle{
      width: 30px!important;
      height: 30px!important;
    }
    /deep/ .el-progress__text{
      top:150%;
    }
  }
</style>
GitHub 加速计划 / eleme / element
54.06 K
14.63 K
下载
A Vue.js 2.0 UI Toolkit for Web
最近提交(Master分支:3 个月前 )
c345bb45 7 个月前
a07f3a59 * Update transition.md * Update table.md * Update transition.md * Update table.md * Update transition.md * Update table.md * Update table.md * Update transition.md * Update popover.md 7 个月前
Logo

旨在为数千万中国开发者提供一个无缝且高效的云端环境,以支持学习、使用和贡献开源项目。

更多推荐