elementui el-upload实现不自动上传,将上传内容放在formData里面,传递给后端

复制代码
 //这种情况一般是要弹出一个弹框进行上传操作


         <el-upload ref="upload" action="" name="fileList" :show-file-list="false" :auto-upload="false" :multiple="true" :headers="header" :on-change="onSuccess" :on-error="onError" > <el-button slot="trigger" size="small" type="primary">选取文件</el-button> </el-upload>
复制代码
复制代码
methods:{
    onSuccess(response) {
        this.filesList.push(response);
    },

  onError(err) {
      var errData = JSON.parse(err.message);
      this.$notify({
        title: "警告",
        message: errData.message,
        type: "warning",
      });
    },

  // 弹框确定按钮
    handlerOk(){
        let formData = new FormData();
     formData.append(
'newAgent', this.addParams.newAgent); formData.append('hostsList', this.addParams.hostsList); //将上传列表循环添加到表单里面 this.filesList.forEach(ele=>{ formData.append('filesList', ele.raw); }) const loading = this.$loading({ lock: true, text: 'Loading', spinner: 'el-icon-loading', background: 'rgba(0, 0, 0, 0.7)' }); this.$axios .post("/api/...........", formData) .then((res) => { if (res.data.code == 200) { this.$message.success("操作成功"); loading.close(); } }); }, }
复制代码

 

posted @   遇你温柔如初  阅读(860)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
· 上周热点回顾(2.24-3.2)
点击右上角即可分享
微信分享提示