根据报错信息可以看出,传入的数据类型应该为数组,而不是对象。因此,需要将数据转换为数组并重新提交。下面是示例代码:
/**
* 原来的代码
*/
const data = {
"relationship": {
"data": {
"type": "groups",
"id": "123456789"
}
}
};
// 发送请求
axios.post(url, data);
/**
* 修改后的代码
*/
const data = {
"relationship": {
"data": [{
"type": "groups",
"id": "123456789"
}]
}
};
// 发送请求
axios.post(url, data);
在原代码的基础上,将 data
内的对象 { "type": "groups", "id": "123456789" }
包裹在一个数组 [{}]
中即可。这样就将数据类型从对象转换为了数组,问题得到解决。