el-upload multiple多文件上传,只传上一个的问题

问题: 使用el-upload上传多文件时,on-success钩子只拿到了一个response,上传只成功上传了一个。

解决:使用:http-requst来覆盖默认的上传行为,可以自定义上传的实现。

代码:

<template>
  <el-upload
    :disabled="disabled"
    :drag="type === ‘drag‘"
    :multiple="true"
    action="/files/upload"
    :http-request="uploadRequest"
    :with-credentials="true"
    :file-list="fileList"
    :before-upload="beforeUpload"
    :on-preview="filePreview"
    :on-remove="fileRemove"
    :on-success="uploadSuccess"
    :on-error="uploadError">
    <template v-if="type === ‘button‘">
      <el-button class="width-7" size="small" type="primary">上传</el-button>
    </template>
    <template v-else-if="type === ‘drag‘">
      <i class="el-icon-upload"></i>
      <div class="el-upload__text">将文件拖到此处,或<em>点击上传</em></div>
    </template>
  </el-upload>
</template>
<script>
  import {mapActions} from ‘vuex‘;

  export default {
    props: {
      fileList: {
        required: true
      },
      type: {
        default: ‘drag‘
      },
      disabled: false,
      fileType: {
        type: String,
        default: ‘all‘
      },
      isAttach: {
        default: false
      }
    },
    data() {
      return {};
    },
    methods: {
      ...mapActions([
        ‘deleteFile‘
      ]),
      beforeUpload(file) {
        if (this.fileType === ‘emergency‘) {
          let str = ‘pdf,bmp,jpg,png,tif,gif,pcx,tga,exif,fpx,svg,psd,cdr,pcd,dxf,ufo,eps,ai,raw‘;
          if (!(str.indexOf(file.name.split(‘.‘).reverse()[0]) > -1)) {
            this.$message.error(‘文件类型错误!‘);
            return false;
          }
        } else if (this.isAttach && file && file.size > 500 * 1024 * 1024) {
          this.$message.error(‘上传文件不得超过500M‘);
          return false;
        }
      },
      filePreview(file) {
        window.open(file.url);
      },
      fileRemove(file) {
        if (file && file.id && !this.isAttach) {
          this.deleteFile(file.id).then(() => {
            this.$emit(‘attachmentDelete‘, file.id);
            this.$message({message: ‘文件删除成功‘, type: ‘success‘});
          }).catch(() => {
            this.$message.error(`文件“${file.name}”删除失败`);
          });
        } else if (this.isAttach && file && file.attachmentId) {
          this.deleteFile(file.attachmentId).then(() => {
            this.$emit(‘attachmentDelete‘, file.attachmentId);
            this.$message({message: ‘文件删除成功‘, type: ‘success‘});
          }).catch(() => {
            this.$message.error(`文件“${file.name}”删除失败`);
          });
        }
      },
      uploadSuccess(response) {
        if (response) {
          this.$message({message: ‘文件上传成功‘, type: ‘success‘});
          this.$emit(‘uploadSuccess‘, response);
        }
      },
      uploadError(err, file) {
        if (err) {
          this.$message.error(`文件“${file.name}”上传失败`);
        }
      },
      uploadRequest(param) {
        let fileObj = param.file;
        let form = new FormData();
        form.append(‘file‘, fileObj);
        this.$axios.$post(`/files/upload`, form, {
          process: function (event) {
            param.file.percent = event.loaded / event.total * 100;
            param.onprogress(param.file);
          }
        }).then(res => {
          this.uploadSuccess(res);
        }).catch(res => {
          this.uploadError();
        });
      }
    }
  };
</script>

原文地址:https://www.cnblogs.com/xinci/p/10529389.html

时间: 2024-08-30 06:01:30

el-upload multiple多文件上传,只传上一个的问题的相关文章

Asp.net core 学习笔记 ( upload/download files 文件上传与下载 )

2017-09-25 refer : https://docs.microsoft.com/en-us/aspnet/core/mvc/models/file-uploads https://www.codeproject.com/Articles/1203408/Upload-Download-Files-in-ASP-NET-Core 这里只说说小文件上传. 先看看前端 js 代码 <input id="inputFile" type="file" /&g

多文档上传(upload multiple documents)功能不能使用怎么办?

问题描述: 在SharePoint 2010的文档库里选择documents标签,然后选择upload document下拉菜单,你会发现upload multiple documents那个按钮是灰色的,不能使用. 当你把鼠标放到那个按钮上悬停,会出现一条提示信息说: This control is currently disabled. You might not have the right permission level to use this, you might need to s

element-ui upload组件多文件上传

之前有一篇写的如何同时传递form表单及upload组件文件,如果有多个upload文件该如何传递呢 上代码 html 1 <el-form-item label="实验信息" prop="expvmInstruction"> 2 <el-upload 3 class="upload-demo" 4 drag 5 ref="uploadhtml" 6 :action="upload_url"

iview Upload组件多文件上传,以及vue文件下载

iview Upload组件多文件上传 系统经常遇到文件上传的问题,iview提供了Upload组建,能够很好的实现文件上传,当然一次上传多个文件也是允许的. 思路:创建一个数组 把需要上传的文件 push到这个数组里面 1.引用组件 2.手动上传,根据官方文档 设置:before-upload ="handleUpload"等于false (1).:before-upload 是 iview Upload 上传组件的一个属性 设置返回值为 false 可以阻止默认上传方式(自动上传模

基于uploadify.js实现多文件上传和上传进度条的显示

uploadify是JQuery的一个插件,主要实现文件的异步上传功能,可以自定义文件大小限制.文件类型.是否自动上传等属性,可以显示上传的进度条.官网地址是http://www.uploadify.com/,进入官网首页(不截图了,其实也没啥看的),可以看到uploadify的标语"Upload files like magic",意思是说使用uploadify上传文件如魔法一般.目前一共分为两个版本,Flash版和HTML5版,不过HTML5版是收费的,如图: 这里我们下载Flas

asp 文件上传(ASPUpload组件上传)

要实现该功能,就要利用一些特制的文件上传组件.文件上传组件网页非常多,这里介绍国际上非常有名的ASPUpload组件 1 下载和安装ASPUpload  要实现该功能,就要利用一些特制的文件上传组件.文件上传组件网页非常多,这里介绍国际上非常有名的ASPUpload组件,它的下载网址是:           http://www.persits.com/aspupload.exe       组件提供者网址是:           http://www.aspupload.com        

文件上传之普通上传

前言 记得去年十月份离开基础邮箱项目组,进入云邮局项目组之后,领导曾经嘱咐我将邮箱的上传模块整理成文档,方便其他同事接手.由于各方面原因迟迟未动手,最近终于下定决心,整理自己的笔记,记录邮箱用到的所有上传方式.大概包括:普通上传.139邮箱小工具上传.Flash上传.HTML5上传(含拖拽上传,分块上传,断点续传,妙传等功能) 普通上传流程如下: 一.应用场景: 单个小文件无需显示上传进度可采用普通上传 二.实现效果: 无刷新上传文件 三.操作步骤: 步骤一.美化原生的input type='f

[转]文件上传原理:Web上传文件的原理及实现

现在有很多Web程序都有上传功能,实现上传功能的组件或框架也很多,如基于java的CommonsFileUpload.还有Struts1.x和Struts2中带的上传文件功能(实际上,Struts2在底层也使用了CommonsFileUpload).在asp.net中也有相应的上传文件的控件. 虽然现在有很多上传组件可以利用,但是了解Web上传文件的原理,对于处理突然出现的问题会有很大的帮助,下面就来讲一下通过浏览器上传文件的基本原理.在了解了原理之后,就可以非常容易地自制满足自身需要的上传组件

HTML5+PHP 实现 保存文件夹相对路径 递归上传 在线浏览

这是最近花了一周多手工马出来的,前段用了MetroUI,后台是ThinkPHP,数据库MySQL,先看看效果吧.由于项目涉及敏感词汇我就码了一下. 1.选择要上传的文件夹,上传以后默认都在根目录下. 2.看看后台管理界面的效果,实现多级目录,可以显示图片内容,返回上一级 正文: 谈到文件夹上传,应该都不觉得难,一个input框加上一个php后台就够了.但是这次的需求说起来容易,但是其实还挺难的.要把一个文件夹的文件递归上传,保存目录结构,能够在浏览器里展示出来,其实是三个过程. [1]上传时要保