el-upload实现多文件上传

复制代码
<template>
    <el-form
      ref="formRef"
      :model="form">
    
        <el-form-item label="Multiple Files">
            <el-upload
              multiple
              :headers="headers" // 一定要设置
              :auto-upload="false"
              list-type="picture-card"
              :on-change="(file, fileList) => {
                form.fileList = fileList
              }"
            >
              <el-icon style="font-size: 28px;">
                <Plus />
              </el-icon>
            </el-upload>
        </el-form-item>
    </el-form>
    <el-button @click="submitForm">Upload</el-button>
</template>

<script>
export default {
    data() {
    
        return {
            form: { fileList: [] },
            headers: { 'Content-Type': 'multipart/form-data' }
        }
    },
    methods: {
        submitForm() {
            let fd = new FormData();
    
            this.form.fileList.map(function(file){
                fd.append('filelist', file.raw);
            })

            uploadFileAPI(fd).then(function(res){
                // ...
            })
        }
    }
}
</script>
复制代码

可能会遇到的问题:文件上传超时错误,后端报java.io.EOFException.

根因:axios全局拦截配置,timeout超时设置可能过短导致,文件大时,会占用比较长的时间,超过超时时间时,请求会被取消,导致文件传输不完整。

posted @   【云】风过无痕  阅读(22)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
点击右上角即可分享
微信分享提示