vue实现element上传多张图片浏览删除功能

 更新时间:2023年10月13日 10:22:31   作者:小郑  
这篇文章主要介绍了vue实现element上传多张图片浏览删除功能,本文结合示例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧

vue原生实现element上传多张图片浏览删除

<div class="updata-component" style="width:100%;">
   <div class="demo-upload-box clearfix">
     <div class="demo-upload-image-box" v-if="imageUrlArr && imageUrlArr.length">
       <div class="demo-upload-image" v-for="(item,index) in imageUrlArr" :key="index">
         <img :src="item">
         <div class="demo-upload-box-cover">
          <!-- 点击删除 -->
           <i class="el-icon-delete" style="position: absolute;left: 30%;top: 80%;z-index:2;color:#fff;"
             @click="handleRemoves(index)"></i>
              <!-- 点击浏览 -->
             <i class="el-icon-zoom-in" @click="handleView(index)" style="position: absolute;left: 56%;top: 80%;z-index:2;color:#fff;"></i>
         </div>
       </div>
     </div>
     <div class="demo-upload-btn" v-show="isshowlng">
       <input ref="uploadInput" type="file" class="file" @change="handleSuccess">
       <i slot="default" class="el-icon-plus"></i>
       <input type="button" class="btn" @click="clickFile" />
     </div>
   </div>
   <!-- 查看大图 -->
   <el-dialog :visible.sync="dialogVisible" :modal-append-to-body="false">
       <img width="100%" :src="bigPicSrc" alt="">
     </el-dialog>
 </div>
data(){
	return{
		bigPicSrc: '',
        imageUrlArr: [],//页面展示url数组
        filesData: [],//file数组
        isshowlng:true,//判断上传图片按钮是否显示
	}
},
methods:{
	// 文件上传接收
    handleSuccess (e) {
      console.log('------',e)
      console.log('imgs.lenght',this.imgs.length)
      var lng=6-this.imgs.length
      console.log('lng',lng)
      let file = e.target
      for (let i = 0; i < file.files.length; i++) {
        this.imageUrlArr.push(window.URL.createObjectURL(file.files.item(i)))
        this.filesData.push(file.files[i])
      }
      console.log('this.filesData',this.filesData)
      console.log('this.filesData.length',this.filesData.length)
      if(this.filesData.length>=lng){
        this.isshowlng=false
      }else{
        this.isshowlng=true
      }
    },
    clickFile () {
      const input = this.$refs.uploadInput
      input.click()
    },
    // 删除上传的案例图
    handleRemoves (index) {
      console.log('删除')
      this.imageUrlArr.splice(index, 1)
      this.filesData.splice(index, 1)
      var lng=6;//限制最多上传6张
      if(this.filesData.length>=lng){
        this.isshowlng=false
      }else{
        this.isshowlng=true
      }
      this.$forceUpdate()
    },
    // 查看大图
    handleView (index) {
      console.log('查看大图')
      this.dialogVisible=true
      this.bigPicSrc = this.imageUrlArr[index]
    },
}
<style>
/* ------------------------- */
.demo-upload-image-box{
  height: 150px;
  /* width: 120px; */
  /* padding: 10px; */
  float: left;
}
.demo-upload-btn{
  width: 115px;
  height: 115px;
  background-color: #fbfdff;
  border: 1px dashed #c0ccda;
  border-radius: 6px;
  text-align: center;
  position: relative;
  float: left;
}
.demo-upload-image{
  width: 117px;
  height: 117px;
  margin-right: 5px;
  display: inline-block;
  position: relative;
}
.demo-upload-image img{
  width: 115px;
  height: 115px;
}
.big-pic{
  position: fixed;
    left: 40%;
    top: 20%;
}
.big-pic img{
  width: 400px;
  height: 300px;
}
.file {
  width: 115px;
  height: 115px;
  display: none;
}
.btn {
  position: absolute;
  top: 0;
  left: 0;
  width: 60px;
  height: 60px;
  background: rgba(0, 0, 0, 0);
  z-index: 10;
  border: none;
  cursor: pointer;
}
.demo-upload-btn .el-icon-plus{
  line-height: 110px;
  font-size: 16px;
  /* position: absolute;
    left: 40px; */
}
.el-icon-plus:before{
  font-size: 30px;
  color: #8c939d;
}
.demo-upload-box-cover{
  background: rgba(0,0,0,0.3);
  width: 100%;
  height: 100%;
  position:absolute;
  left:0;
  top:0;
  border-radius:5px;
}
</style>

到此这篇关于vue实现element上传多张图片浏览删除功能的文章就介绍到这了,更多相关vue element上传多张图片内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • Vue面试题及Vue知识点整理

    Vue面试题及Vue知识点整理

    这篇文章主要介绍了Vue面试题及Vue知识点整理,本文给大家介绍的非常详细,具有一定的参考借鉴价值,需要的朋友参考下吧
    2018-10-10
  • element实现合并单元格通用方法

    element实现合并单元格通用方法

    这篇文章主要介绍了element实现合并单元格通用方法,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-11-11
  • Vue + element 实现多选框组并保存已选id集合的示例代码

    Vue + element 实现多选框组并保存已选id集合的示例代码

    这篇文章主要介绍了Vue + element 实现多选框组并保存已选id集合,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2020-06-06
  • vue3 使用 vue3-video-play实现在线视频播放

    vue3 使用 vue3-video-play实现在线视频播放

    这篇文章主要介绍了vue3 使用 vue3-video-play 进行在线视频播放,本文通过实例代码给大家介绍的非常详细,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下
    2023-06-06
  • Vue+Openlayer批量设置闪烁点的实现代码(基于postrender机制)

    Vue+Openlayer批量设置闪烁点的实现代码(基于postrender机制)

    本篇文章给大家介绍基于postrender机制使用Vue+Openlayer批量设置闪烁点的实现代码,代码简单易懂,对大家的学习或工作具有一定的参考借鉴价值,需要的朋友参考下吧
    2021-09-09
  • Vue使用Canvas生成随机大小且不重叠圆

    Vue使用Canvas生成随机大小且不重叠圆

    Canvas是HTML5中新增的元素,专门用来绘制图形,下面这篇文章主要给大家介绍了关于Vue使用Canvas生成随机大小且不重叠圆的相关资料,文中通过示例代码介绍的非常详细,需要的朋友可以参考下
    2021-11-11
  • vue webuploader 文件上传组件开发

    vue webuploader 文件上传组件开发

    本篇文章主要介绍了vue webuploader 文件上传组件开发,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-09-09
  • vue @vuelidate父子组件绑定注意事项

    vue @vuelidate父子组件绑定注意事项

    Vue@vuelidate父子组件验证时,不能直接绑定,需在子组件验证方法内部进行绑定,以避免父组件验证时包含子组件的验证
    2025-02-02
  • vue3全局导入bootstrap5方式

    vue3全局导入bootstrap5方式

    这篇文章主要介绍了vue3全局导入bootstrap5方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教
    2023-10-10
  • Vue开发中Jwt的使用详解

    Vue开发中Jwt的使用详解

    Vue中使用JWT进行身份认证也是一种常见的方式,它能够更好地保护用户的信息,本文主要介绍了Vue开发中Jwt的使用详解,具有一定的参考价值,感兴趣的可以了解一下
    2023-12-12

最新评论