上传文件 后台参数偶尔为空_element多文件上传,带参数

需求年年有,今年特别多,要求:在新建成员的时候,会上传多个文件,这样后台只写一个接口,新建成员信息和文件 只走一个新建的接口

             <el-upload
                  class="upload-demo"
                  action
                  multiple
                  :http-request="uploadFile"
                  :on-preview="handlePreview"
                  show-file-list
                  :beforeUpload="beforeAvatarUpload"
                  :on-change="handleChange"
                  :auto-upload="false"
                  ref="upload"
                >
                  <i class="el-icon-circle-plus clickUpload">
                    <span>点击上传</span>
                  </i>
                  <div slot="tip" class="el-upload__tip lineHeight">上传用户文件,文件大小不超过5M</div>
              </el-upload>    
            <el-button type="primary" @click="onSubmit()">确定</el-button>

:auto-upload="false" 是让文件不立马走接口

 // 文件预览
    handlePreview(file) {
      console.log(file)
    },
    handleChange(file) {
      const isLt2M = file.size / 1024 / 1024 < 5
      if (!isLt2M) {
        this.$message({
          message: '上传文件大小不能超过 5MB!',
          type: 'warning',
        })
        this.$refs.upload.clearFiles()
        return false
      }
    },
    // 文件上传
    uploadFile(param) {
      this.fileData.append('file', param.file)
    },
  // 确定
    onSubmit() {
   let form = { name:1, sex:'男', age: '20', like:'sing' } 
    this.fileData = new FormData()
    for (let key in form) {
         this.fileData.append(key, form[key])
      }
      this.$refs.upload.submit()
     }

674835702c6251ccee23b5a21d5e10db.png
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值