美文网首页
使用el-upload不上传文件,触发不了http-reques

使用el-upload不上传文件,触发不了http-reques

作者: cghneany | 来源:发表于2020-06-09 15:24 被阅读0次

    解决方案:放弃使用this.$refs.upload.submit(); 获取选择文件,使用FormData上传

    <el-upload
      ref="upload"
      name="attachment"
      :limit="1"
      action=""
      :auto-upload="false"
      :on-exceed="onExceed"
      :on-change="onChange"
      :on-remove="onRemove">
      <el-link :underline="false" type="primary">选择文件</el-link>
    </el-upload>

    onExceed(files, fileList) {
        this.$message.error('只能上传一个文件')
    },
    onChange(file, fileList) {
        this.launchDialogForm.attachment = file.raw
    },
    onRemove(file, fileList) {
        this.launchDialogForm.attachment =null
    }

    var formData =new FormData()
    formData.append('tradeNumber',this.launchDialogForm.tradeNumber)
    formData.append('attachment',this.launchDialogForm.attachment)
    createWorksheet(formData).then(response => {
       console.log(response)
    })

    export function createWorksheet(params) {
        return request({
           url:'/wo/create',
           method:'post',
           data: params
        })
    }

    后台:

    @PostMapping("/create")
    public ResponseResult createWorksheet(
                 @RequestParam(value ="attachment",required =false) MultipartFile attachment,
                 WorksheetParam param
    ) {
           return ResponseResult.success();
    }

    相关文章

      网友评论

          本文标题:使用el-upload不上传文件,触发不了http-reques

          本文链接:https://www.haomeiwen.com/subject/ytgstktx.html