前端傳遞數據到后台的兩種方式;創建一個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
      })
    },

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM