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', }) }) }
一定要传对象,不可以直接传参数,记住就对了!
分类:
vue
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 分享4款.NET开源、免费、实用的商城系统
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了