当前位置: 首页 > article >正文

【el-upload】el-upload组件 - list-type=“picture“ 时,文件预览展示优化

目录

  • 问题图
  • el-upload
  • 预览组件 PicturePreview
  • 效果展示

问题图

在这里插入图片描述

el-upload

<el-upload
  ref="upload"
  multiple
  drag
  action="#"
  :auto-upload="false"
  :file-list="fileList"
  name="files"
  :accept="`.png,.jpg,.jpeg,.JGP,.JPEG,.PNG,.doc,.docx,.xls,.xlsx${isTz ? ',.mp4,.MP4' : ''}`"
  :on-change="beforeAvatarUpload"
  list-type="picture"
>
  <i class="el-icon-upload" />
  <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
  <div slot="tip" class="el-upload__tip">
    支持上传png/jpg/jpeg/doc/docx/xls/xlsx文件,且不超过5M
  </div>
  <!-- 【使用组件】 -->
  <div slot="file" slot-scope="{ file }">
    <PicturePreview :file="file" @remove="removeFile" />
  </div>
</el-upload>

import PicturePreview from '@/components/PicturePreview'

components:{PicturePreview}

removeFile(file) {
  this.$refs.upload.handleRemove(file)
},

预览组件 PicturePreview

<!-- el-upload组件 - list-type="picture" 时,文件预览展示优化 -->
<template>
  <div class="file_container">
    <div class="file">
      <el-image
        v-if="/(gif|jpg|jpeg|png|GIF|JPG|JPEG|PNG)$/.test(fileType)"
        :src="file.url"
        :preview-src-list="[file.url]"
      />
      <i v-else class="el-icon-tickets" />
    </div>
    <div class="name">{{ file.name }}</div>
    <i class="el-icon-close" @click="$emit('remove', file)" />
  </div>
</template>

<script>
export default {
  name: 'PicturePreview',
  components: {},

  props: {
    file: {
      type: Object,
      required: true
    }
  },

  data() {
    return {}
  },

  computed: {
    fileType() {
      return this.file.name.split('.').pop()
    }
  },

  watch: {},

  created() {},

  methods: {}
}
</script>

<style lang='scss' scoped>
.file_container {
  position: relative;
  .file {
    $size: 80px;
    width: $size;
    height: $size;
    background-color: #f7f7f7;
    position: absolute;
    left: -85px;
    top: -5px;

    display: flex;
    align-items: center;
    justify-content: center;
    .el-image {
      width: 100%;
      height: 100%;
    }
    .el-icon-tickets {
      font-size: 30px;
    }
  }
  .name {
  }
  .el-icon-close {
    position: absolute;
    top: 5px;
    right: 5px;
    font-size: 10px;
  }
}
</style>

效果展示

在这里插入图片描述


http://www.kler.cn/a/596382.html

相关文章:

  • strstr!!!
  • springCloud集成tdengine(原生和mapper方式) 其二 原生篇
  • 【嵌入式学习】计算机自动运行小组件
  • 基于大模型的甲状舌管囊肿全流程预测与临床方案研究报告
  • python学习笔记--实现简单的爬虫(一)
  • vlan路由间配置
  • Pytorch中的torch.utils.data.Dataset 类
  • TSL 和 SSL 是什么?它们有何关系?
  • 3.20-epoll 函数
  • 通俗易懂搞懂@RequestParam 和 @RequestBody
  • 2025年01月03日微创网络(杭州银行外包)前端面试
  • OpenCV Objdetect 模块使用指南
  • 尝试将相机采集图像流程封装成相机采图类
  • 微信小游戏:跳一跳,自动化操作
  • BlockChain.java
  • 西门子200smart之modbus_TCP(做从站与第三方设备)通讯
  • 【机器学习】手撕封装PCA——将高维数据映射到低维数据的过程
  • TPCTF 2025 web 复现
  • 【unordered_set和unordered_map】—— 我与C++的不解之缘(二十七)
  • wyq01