首页 > 其他分享 >文件上传图片形式

文件上传图片形式

时间:2022-12-15 15:58:43浏览次数:31  
标签:文件 return filePath fileList util file 图片 上传 size

<template>
  <div>
    <el-upload
      style="margin-top: 10px;"
      class="upload-demo"
      list-type="picture-card"
      action="http://192.168.1.115:9999/sdfs/file/uploadFile"
      :on-remove="handleRemoveF"
      :on-success="handleSuccessF"
      :before-upload="handleBefore"
      :file-list="fileList">
      附件上传
      <div slot="tip" class="el-upload__tip">文件大小不超过{{size}}MB</div>
      <div slot="file" slot-scope="{file}">
        <div style="width: 146px;height: 146px;display: flex;justify-content: center;align-items: center;
                  padding: 3px;">
          <span>{{ file.name }}</span>
        </div>

        <span class="el-upload-list__item-actions">
                      <span class="el-upload-list__item-preview" @click="handleDown(file)">
                          <i class="el-icon-download"></i>
                      </span>
                      <span class="el-upload-list__item-delete" @click="handleRemoveF(file)">
                          <i class="el-icon-delete"></i>
                      </span>
                  </span>
      </div>
    </el-upload>
  </div>
</template>

<script>
import util from '@/libs/util'
export default {
  name: "UploadFile",
  props: {
    fileList:{
      type: Array,
      default: () => {
        return []
      }
    },
    size:{
      type: Number,
      default: () => {
        return 1
      }
    }
  },
  watch:{

  },
  data() {
    return {
      uploadUrl: util.baseUrl + '/sdfs/file/uploadFile',
      file:''
    }
  },
  methods: {
    handleRemoveF(file, fileList) {
      for(let i in this.fileList){
        if(file.data.filePath==this.fileList[i].data.filePath){
          this.fileList.splice(i,1)
        }
      }
    },
    handleDown(file) {
      window.open(util.baseUrl + '/sdfs/file/download?filePath=' + file.data.filePath)
    },
    handleBefore(file){
      const isLt2M = file.size / 1024 / 1024 < this.size;
      if (!isLt2M) {
        this.$Message.error('上传文件大小不能超过'+ this.size +'MB!')
      }
      return isLt2M;
    },
    handleSuccessF(res, file) {
      res.name = file.name
      this.fileList.push(res)
    }
  }
}
</script>

<style scoped>

</style>

 

标签:文件,return,filePath,fileList,util,file,图片,上传,size
From: https://www.cnblogs.com/Byme/p/16985196.html

相关文章

  • C# 批量打印图片,Image转PDF并可多台打印机打印(Spire.PDF、去水印)
    版本:一定要是Spire.PDF5.10.2(包括5.10.2)以前的。如果版本不一样,可以更新。如果版本大于 5.10.2,无论是生成还是打印PDF,水印都是去不掉的。FreeSpire.PDF是只能打印......
  • Go语言获取路径的文件名、后缀
    packagemainimport( "fmt" "path" "path/filepath")funcmain(){ filePath:="D:/DDPS/log/log.txt" paths,fileName:=filepath.Split(filePath) fm......
  • CAD标注样式设置文件怎么输入使用?
    上节教程文章中小编给大家分享了CAD标注样式文件保存的详细操作步骤,那么,在下次CAD设计过程中,如果想要调用该标注样式,该如何将CAD标注样式设置文件输入使用呢?本文小编就来给......
  • jsp web 大文件上传源代码
    ​我们平时经常做的是上传文件,上传文件夹与上传文件类似,但也有一些不同之处,这次做了上传文件夹就记录下以备后用。这次项目的需求:支持大文件的上传和续传,要求续传支持所......
  • element-ui 文件上传多个
      <template><div><el-uploadref="upload":action="action":limit="5":file-list="fileList":on-exceed="handleExcee......
  • uview图片上传多张
    <template><viewclass="contain-box"><u-navbar:title="title":is-back="true"back-icon-color="#fff":background="background"......
  • elment-ui 文件上传
      <template><div><el-uploadref="upload":action="action":limit="1":file-list="fileList":on-exceed="handleExcee......
  • tomcat 不能访问中文名称文件
      Tomcat6.0下下载中文名称的文件,会报404错误       根据错误发现中文名称被转化了,因此必然找不到%E5%AE....xls这样的文件   解决方案:在server.xml......
  • QT 绘制YUV420图片
    Qt不能直接绘制YUV数据,需要使用QOPenGLWidget使用OPENGL来绘制,并且这样显示直接用的显卡绘制使用QOPenGLWidget绘制YUV数据,我们需要继承QOpenGLWidget和QOpenGLFunctions(......
  • Python14 文件读写和编码&OS、path模块的使用
    编码文件读写操作#作者:咸瑜file=open("text.txt","r",encoding="utf-8")print(file.readlines())#['姓名:咸瑜\n','年龄:18\n','籍贯:广东·惠州']file.clo......