Loading

上传文件携带参数

使用el-upoad组件自定义上传
使用formData.append()来添加参数
直接在控制台打印formData参数为空 获取formData参数使用formData.get()

<el-upload class="upload" ref="uploadBox" action="" :multiple="false" :limit="1" accept=".xls,.xlsx" :file-list="fileList" :auto-upload="false" :http-request="upload">
            <el-button size="mini" type="primary">选择文件</el-button>
</el-upload>
<el-button style="margin-left:15px" size="mini" type="primary" icon="el-icon-upload" @click="btnClick">上传</el-button>
async upload (item) {
      const formData = new FormData()
      formData.append('file', item.file)
      formData.append('bankId', this.form.bankId)
      formData.append('appendFlag', this.form.appendFlag)
      formData.append('allSuccessFlag', this.form.allSuccessFlag)
      formData.append('successRemark', this.form.successRemark)
      this.importLoading = true
      const res = await api.importBill(formData).finally(() => {
        this.importLoading = false
      })
    },
async btnClick () {
      const files = this.$refs.uploadBox.uploadFiles
      // 判断是否已选择文件
      if (files.length > 0) {
        this.$refs.uploadBox.submit()
      } else {
        this.$message({
          message: '请先选择文件!!!',
          type: 'warning'
        })
      }
    },
posted @ 2022-08-30 09:09  资深if-else侠  阅读(183)  评论(0编辑  收藏  举报