上传文件的代码

单独上传

<el-upload v-model:file-list="fileList" accept=".pdf"
                    :action="`${this.$http.BASE_URL}/graduationOperate/hooking`" :show-file-list="false"
                    :before-upload="beforeUpload" :disabled="progressShow" :on-success="handleSuccess" multiple>
                    <el-button type="success" style="margin-left:20px;">上传</el-button>
                </el-upload>

多个上传 走一个接口

<template>
         <el-upload v-model:file-list="fileListHitch" :auto-upload="false" :on-change="hitchApi"
                    :action="hitchAction" multiple :limit="10" accept=".pdf" :show-file-list="false"
                    style="margin:0 15px;">
                    <el-button type="success" style="margin-left:20px;">上传</el-button>
                </el-upload>
</template>

<script>
export default {
     
  methods: {
   
   //批量挂接
   hitchApi(file, fileList) {
       this.fileListHitch = fileList;
       // 每次触发时先清除之前的定时器
       clearTimeout(this.debounceTimer);
       // 设置新的定时器,延迟 300ms 后执行上传
       this.debounceTimer = setTimeout(() => {
           // 确保文件列表是最新的
           const currentFileList = [...this.fileListHitch];
           if (currentFileList.length === 0) return;
           const formData = new FormData();
           currentFileList.forEach((file) => {
               formData.append('file', file.raw); // 注意字段名要和后端一致
           });
           axios.post(`${this.$http.BASE_URL}/graduationOperate/hooking`, formData, {
               headers: {
                   'Content-Type': 'multipart/form-data',
               },
           })
               .then((response) => {
                   this.$message.success('上传成功');
                   this.fileListHitch = [];
                   this.search();
                   this.getTree();
                   // console.log(this.fileListHitch, 'liebiao')
               })
               .catch((error) => {
                   this.$message.error('上传失败');
                   console.error(error);
               });
       }, 300); // 300ms 延迟足够覆盖连续选择文件的场景
   },
}

}
</script>

<style>

</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值