首页 > 其他分享 >toFormData.js?9ba3:98 Uncaught (in promise) TypeError: target must be an object

toFormData.js?9ba3:98 Uncaught (in promise) TypeError: target must be an object

时间:2023-03-09 21:13:58浏览次数:46  
标签:TypeError depart target confirm res object datainfo type

toFormData.js?9ba3:98 Uncaught (in promise) TypeError: target must be an object

在做vue前端开发时,需要报错,,困扰我这个菜鸟挺久的,后来终于解决了,这里记录一下:

 

 其实,上面已经很清楚的提示了 目标需要一个object对象。找到你前端代码,看你传参的方式,我之前有问题的传参是这样的:

const open = (datainfo) => { 
 ElMessageBox.confirm( 'proxy will permanently delete the file. Continue?', 'Warning', {
   confirmButtonText: 'OK', 
   cancelButtonText: 'Cancel', 
   type: 'warning',
   callback:(action,instance)=>{
        if(action==="confirm"){
         getDepart(datainfo).then(res=>{
        datapa.formData.depart=res["depart"]
    
     })
    }
   }
    }
  )
    .then(() => {
      ElMessage({
        type: 'success',
        message: 'Delete completed',
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: 'Delete canceled',
      })
    })
}

修改后,正确的传参方式是:

const open = (datainfo) => { 
 ElMessageBox.confirm( 'proxy will permanently delete the file. Continue?', 'Warning', {
   confirmButtonText: 'OK', 
   cancelButtonText: 'Cancel', 
   type: 'warning',
   callback:(action,instance)=>{
        if(action==="confirm"){
     let data={"depart",datainfo} //注意使用Promise时,给后端传参的数据类型必须是object类型的
         getDepart(data).then(res=>{
        datapa.formData.depart=res["depart"]
    
     })
    }
   }
    }
  )
    .then(() => {
      ElMessage({
        type: 'success',
        message: 'Delete completed',
      })
    })
    .catch(() => {
      ElMessage({
        type: 'info',
        message: 'Delete canceled',
      })
    })
}

一定要传对象,不可以直接传参数,记住就对了!

标签:TypeError,depart,target,confirm,res,object,datainfo,type
From: https://www.cnblogs.com/pingguomang/p/17201406.html

相关文章