element上传图片,调取接口传值,参数FormData为空

在这里插入图片描述

需求

输入完reason,选完文件后,点击提交按钮后 调取接口。

遇到的问题

上传文件orderFile 字段一直为空
在这里插入图片描述
打印了发现,上传文件也是有值得。但是传到接口中就为空

原因

json里边不能放file,但是formData里可以放 file 也可以放json

应该说是formData里可以放任何你需要提交的东西

所以 修改后将需要传给接口的字段 放到formData里,进行传值

修改后

有值了。
在这里插入图片描述

错误写法

在这里插入图片描述

正确写法

在这里插入图片描述

完整代码

  <el-dialog :modal="false" v-el-drag-dialog :visible.sync="openVisible" :close-on-click-modal="false" width="30%">
      <div style="margin: 40px 20px 20px 0px">
        <div class="inputFlex">
          <div class="inputTitle">{{ $t('outSideShelf.reason') }}</div>
          <el-input v-model="reason" clearable style="margin: 0px 5px;" />
        </div>
        <el-button class="btn">
          <el-upload class="filter-item" ref="upload" action="" accept=".csv,xlsx" :multiple="false" :auto-upload="false"
            :on-change="handleChange">
            <el-button icon="el-icon-plus" size="mini" type="primary">{{
              $t("outSideShelf.upWorkOrder")
            }}</el-button>
          </el-upload>
        </el-button>
      </div>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="onSubmit">Submit</el-button>
      </div>
    </el-dialog>
 data() {
    return {
      openVisible: false,
      uplodFile: {},
      uploadParams: {},
      reason: ''

    };
  },
//上传事件
 handleChange(file, fileList) {
      this.uploadfile = file.raw;
    },
    //提交
    onSubmit() {
      const params = new FormData();
      params.append("mode", 'RACK');
      params.append("reason", this.reason);
      params.append("orderFile", this.uploadfile);
      console.log(params)
      getSubmit(params).then((res) => {
        if (res.code == 0) {
          this.$infoMsg.showInfoMsg(res.msg, this);
          this.openVisible = false
          this.$router.push({
            path: "/outsideShelf" + "1" + "/" + "Outside Shelf Dispatch",
          });
        } else {
          this.$infoMsg.showErrorMsg(res.msg, this);
        }
      });

    },
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值