【发布时间】:2019-07-19 03:45:51
【问题描述】:
我有一个对象数组。我想使用 axios 在发布请求中将这些作为数据发送:
const instance = axios.create({
responseType: 'json'
})
const options = {
data: [{ title: 'test1' }, { title: 'test2' }, { title: 'test3' }]
}
axios.post(route, null, options)
但是,当我在服务器上解析数据时,它会从数组转换为对象。当我在 Chrome 开发者工具中查看请求负载时,数据被发送为:
{
0: { title: 'test1' },
1: { title: 'test2' },
2: { title: 'test3' }
}
所以看起来数组在发送之前被转换为对象格式。这是预期的行为吗? (数组对象的属性不会以这种方式转换。)有没有办法解决这个问题?
【问题讨论】:
标签: javascript json ajax post axios