Vue3接口数据报错TypeError: target must be an object

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',
      })
    })
}
复制代码

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

posted @   苹果芒  阅读(4550)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示