前端传递数据到后台的两种方式;创建一个map或者创建一个FormData对象

一、构建一个map

getAllDeptAllUsers(){
          const modleCode = {'auditMenuId': this.auditMenuId,
            'enterpriseId': this.$store.getters.enterpriseId};
          deptJs.getAllDeptAllUsers(modleCode).then(res=>{
            this.departmentList = res.data;
          })
        },

二、通过const data = new FormData()创建一个FormData对象

handleUploadChange(file, fileList) {
      if(this.auditors == ''||this.auditors == null){
        this.$message.error('上传前请先选择审核人')
        return
      }
      if (file.name.lastIndexOf('.') < 0) {
        this.$message.error('上传文件只能是xls、xlsx格式!')
        return
      }
      const testMsg = file.name.substring(file.name.lastIndexOf('.') + 1).toLowerCase()
      const extensionXLS = testMsg == 'xls'
      const extensionXLSX = testMsg == 'xlsx'
      if (!extensionXLS && !extensionXLSX) {
        this.$message.error('上传文件只能是xls、xlsx格式!')
        return
      }
      const isLt2M = file.size / 1024 / 1024 < 2
      if (!isLt2M) {
        this.$message.error('上传文件不能超过 2MB!')
        return
      }
      console.log('import continue')
      this.importLoading = true
      this.importDisabled = true
      const data = new FormData()
      data.append('file', file.raw)
      data.append('ids',this.auditors)
      data.append('mesNodeNo',this.dataObj.mesNodeNo)
      Node.importExcel(data).then(response => {
        if (response.success == true) {
          this.open2(response.msg)
          this.importLoading = false
          this.importDisabled = false
          this.getList()
        } else {
          this.open2(response.msg)
          this.importLoading = false
          this.importDisabled = false
        }
      }).catch(() => {
        this.open2('抱歉,导入失败')
        this.importLoading = false
        this.importDisabled = false
      })
    },
原文地址:https://www.cnblogs.com/zwh0910/p/13991463.html