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上传多张图片内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!

相关文章

  • uniapp项目国际化标准的配置与实现

    uniapp项目国际化标准的配置与实现

    UniApp是一种基于Vue.js的跨平台开发框架,可以快速地开发同时运行在多个平台的应用程序,这篇文章主要介绍了uniapp项目国际化标准的配置与实现,需要的朋友可以参考下
    2023-11-11
  • vue-cli3配置多项目并按项目分别实现打包

    vue-cli3配置多项目并按项目分别实现打包

    这篇文章主要介绍了vue-cli3配置多项目并按项目分别实现打包方式,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2023-01-01
  • Vue3使用vue-router如何实现路由跳转与参数获取

    Vue3使用vue-router如何实现路由跳转与参数获取

    这篇文章主要介绍了Vue3使用vue-router如何实现路由跳转与参数获取,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-03-03
  • vue-cli3 karma单元测试的实现

    vue-cli3 karma单元测试的实现

    这篇文章主要介绍了vue-cli3 karma单元测试的实现,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2019-01-01
  • 装饰者模式在日常开发中的缩影和vue中的使用详解

    装饰者模式在日常开发中的缩影和vue中的使用详解

    这篇文章主要为大家介绍了装饰者模式在日常开发中的缩影和vue中的使用详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2022-12-12
  • 解决vue3项目打包后部署后某些静态资源图片不加载问题

    解决vue3项目打包后部署后某些静态资源图片不加载问题

    这篇文章主要给大家介绍了如何解决vue3项目打包后部署后某些静态资源图片不加载问题,文中通过图文结合的方式讲解的非常详细,有需要的朋友可以参考下
    2024-05-05
  • vue自定义实例化modal弹窗功能的实现

    vue自定义实例化modal弹窗功能的实现

    这篇文章主要介绍了vue自定义实例化modal弹窗,Vue.extend 属于Vue的全局 api,在实际业务开发中我们很少使用,因为相比常用的 Vue.component写法使用 extend 步骤要更加繁琐一些,本文结合实例代码给大家介绍的非常详细,需要的朋友参考下
    2022-09-09
  • Vue.js中provide/inject实现响应式数据更新的方法示例

    Vue.js中provide/inject实现响应式数据更新的方法示例

    这篇文章主要介绍了Vue.js中provide/inject实现响应式数据更新,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2019-10-10
  • Vue3+TS项目中eslint、prettier安装配置详细指南

    Vue3+TS项目中eslint、prettier安装配置详细指南

    为了更好的统一项目的代码风格,因此在编写时就可以使用eslint+prettier,它们不仅能方便代码编写,还能避免不必要的错误,让代码变得更加严谨,这篇文章主要给大家介绍了关于Vue3+TS项目中eslint、prettier安装配置的相关资料,需要的朋友可以参考下
    2024-07-07
  • Vue3中vue-router的使用方法详解

    Vue3中vue-router的使用方法详解

    Vue Router 是 Vue 的官方路由,它与 Vue.js 核心深度集成,让用 Vue.js 构建单页应用变得轻而易举,本文将通过简单的示例为大家介绍一下vue-router的使用,需要的可以参考一下
    2023-06-06

最新评论