关于vue.js:vueelement-upload组件上传多次调用接口解决方案

1.开发环境 vue+element
2.电脑系统 windows11专业版
3.在应用element的过程中,遇到upload组件上传屡次调用接口,上面我来分享一下解决办法:

// tempalte代码
<el-upload
    action=""
    multiple
    :on-change="FileChange"
    :show-file-list="false"
>
  <el-button size="small" type="primary">新增</el-button>
</el-upload>
//return 代码:
FileUploadNumber:0,
fileList:[],
FileChange (file, fileList){
      console.log(file);
      console.log(fileList);
      this.fileList = fileList;
      this.FileUploadNumber += 1;
      let length = fileList.length;
      this.FileUploadNumber = Math.max(length, this.FileUploadNumber);
      // setTimeout(() => {
      //
      // });
      if (length !== this.FileUploadNumber) {
        // console.log('以后length为', length, '不是最大值');
        return false;
      } else {
        console.log('以后length为最大值', length);
        //这里就能够调用你上传文件的接口了
        const formData = new FormData();
        this.fileList instanceof Array && this.fileList.map(item=>{
          formData.append("sdkSymbolFiles",item.raw);
        });
       
      }
    },

4.本期的分享到了这里就完结啦,心愿对你有所帮忙,让咱们一起致力走向巅峰。

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理