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

【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>

效果展示

在这里插入图片描述

相关文章:

  • dfs(二十)257. 二叉树的所有路径
  • /proc/[pid]/maps介绍和pmap介绍、RSS
  • 《深入理解 TypeScript:函数类型与泛型全解析》(万字长文)
  • 【MyDB】5-索引管理之 1-索引管理思路概览
  • Centos7配置本地yum源
  • 大白话读懂java对象创建的过程
  • 织梦DedeCMS数据库表说明大全
  • django入门教程之request和reponse【二】
  • Windows 图形显示驱动开发-WDDM 3.0功能- 硬件翻转队列(六)
  • 联想拯救者触摸板会每次开机都自动关闭、联想笔记本触摸板关闭、笔记本电脑触摸板自动关闭的解决方法
  • 演员马晓琳正式加入创星演员出道计划,开启演艺事业新篇章
  • 基于YOLOv8与ByteTrack的车辆行人多目标检测与追踪系统
  • @maptalks/gl-layers中的VectorTileLayer的setStyle属性的全部line配置
  • 群体智能优化算法-模拟退火优化算法(Simulated Annealing, SA,含Matlab源代码)
  • 前端Tailwind CSS面试题及参考答案
  • 实时时钟芯片HYM1381的使用(51单片机)
  • 在K8S中挂载 Secret 到 Pod
  • 【C#知识点详解】ExcelDataReader介绍
  • day3 微机运算基础
  • 【LINUX操作系统】 动静态库的链接原理
  • A股三大股指低收:汽车股领涨,大金融走弱,两市成交近1.1万亿元
  • 媒体评欧阳娜娜遭民进党当局威胁:艺人表达国家认同是民族大义
  • 四川内江警方通报一起持刀伤人致死案:因车辆停放引起,嫌犯被抓获
  • 辽宁盘山县一乡镇幼儿园四名老师被指多次殴打一女童,均被行拘
  • 沧州低空经济起飞:飞行汽车开启千亿赛道,通用机场布局文旅体验
  • 盛和资源海外找稀土矿提速:拟超7亿元收购匹克,加快推动坦桑尼亚项目