前几天遇到一个post传参的问题 需要同时拼接字符串 并且在body内传入实体的特此记录一下

 js 文件

首先记得引入axios

import request from '@/router/axios'

// 导入问题
export function leadProblem(obj,id) {
  return request({
    url: '/bms/problemdetails/importQuestion/'+id,
    method: 'post',
    data:obj,
    headers: {
      'Content-Type': 'multipart/form-data; boundary = ' + new Date().getTime()
    } 
  })
}

vue  中接口调用这个 方法  记得导入这个方法

import { leadProblem} from '@/api/auditAdminister/problem';

 upload1(){
         let pams = {
           projectId: this.daoID,
         };
         this.formData1.delete('projectId')
         this.formData1.append('projectId',pams.projectId)
        // console.log(this.formData1)
       leadProblem(this.formData1,this.daoID).then(response => {
            console.log('提交参数',response)
            if (response.data.code == 0) {
                this.$message.success('问题导入成功!');
            } else {
                this.$message({ message: response.data.msg, type: "error" });
                this.formData1.delete('file');
                this.$refs.upload1.clearFiles();
                this.fileList1 = [];
            }
          })
          .catch(err => {
              console.log(err)
            //this.$message({ message: "导入失败", type: "error" });
          });



},

Logo

前往低代码交流专区

更多推荐