欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue3 el-upload單張圖片回顯、編輯、刪除功能實(shí)現(xiàn)

 更新時(shí)間:2023年12月21日 11:59:29   作者:ztwelve  
這篇文章主要介紹了vue3 el-upload單張圖片回顯、編輯、刪除功能實(shí)現(xiàn),圖片回顯時(shí)隱藏上傳區(qū)域,鼠標(biāo)懸浮顯示遮罩層進(jìn)行編輯、刪除操作,刪除圖片后顯示上傳區(qū)域,本文通過實(shí)例代碼分享實(shí)現(xiàn)方法,感興趣的朋友一起看看吧

vue3 el-upload單張圖片回顯、編輯、刪除功能

在這里插入圖片描述

圖片回顯時(shí)隱藏上傳區(qū)域,鼠標(biāo)懸浮顯示遮罩層進(jìn)行編輯、刪除操作,刪除圖片后顯示上傳區(qū)域
vue部分:
①el-upload沒有限制上傳文件數(shù)量,如果limit=1,那么點(diǎn)擊編輯時(shí)不會(huì)觸發(fā)on-change事件,需要先清除當(dāng)前文件,頁面會(huì)出現(xiàn)上傳區(qū)域;
②刪除按鈕click.stop阻止事件冒泡,刪除后不會(huì)彈出上傳圖片窗口

<template>
  <el-upload class="upload-demo" drag action="#" accept=".jpg,.png" :on-change="handleChange" :auto-upload="false"
    ref="uploadRef" :show-file-list="false">
    <!-- 圖片上傳框 -->
    <div v-if="!fileList.length">
      <el-icon class="el-icon--upload"><upload-filled /></el-icon>
      <div class="el-upload__text">
        Drop file here or <em>click to upload</em>
      </div>
    </div>
    <!-- 回顯及遮罩層 -->
    <div v-else>
      <img :src="fileList[0].url" alt="">
      <div class="mask">
        <el-icon size="50">
          <Edit />
        </el-icon>
        <el-icon size="50" @click.stop="handleDelete">
          <Delete />
        </el-icon>
      </div>
    </div>
    <template #tip>
      <div class="el-upload__tip tip">
        jpg/png files with a size less than 500kb
      </div>
    </template>
  </el-upload>
</template>

ts部分:

<script setup lang="ts">
import { ref } from 'vue'
import type { UploadFile, UploadUserFile } from 'element-plus'
let fileList = ref<UploadUserFile[]>([])
const uploadRef = ref()
const handleChange = (file: UploadFile) => {
  //如果上傳的圖片沒有url字段,手動(dòng)生成
  if (!file.url) file.url = URL.createObjectURL(file.raw as any)
  fileList.value[0] = file
}
const handleDelete = () => {
  //刪除時(shí)清除所有已上傳圖片
  uploadRef.value.clearFiles()
  fileList.value = []
}
</script>

樣式:

<style lang="scss" scoped>
:deep(.el-upload) {
  height: 100%;
}
:deep(.el-upload-dragger) {
  height: 100%;
  padding: 10px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  box-sizing: border-box;
}
 .upload-demo {
    width: 300px;
  	height: 200px;
  }
  .tip {
    color: red;
  }
//遮罩層
.mask {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(100, 100, 100, 0.5);
  color: #ffffff;
  opacity: 0;
  display: flex;
  justify-content: center;
  align-items: center;
  &:hover {
    opacity: 1;
  }
  .el-icon {
    margin: 0 10px;
    &:hover {
      color: #70aeed;
    }
  }
}
</style>

到此這篇關(guān)于vue3 el-upload單張圖片回顯、編輯、刪除功能的文章就介紹到這了,更多相關(guān)vue3 el-upload圖片回顯編輯、刪除內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論