Axios的params返回的数据是一个对象而不是数组的问题可以通过以下解决方法来解决:
axios.get('/api/data', { params: { key: 'value' } })
.then(response => {
const dataArray = Object.keys(response.data).map(key => response.data[key]);
console.log(dataArray); // 数组形式的数据
})
.catch(error => {
console.error(error);
});
app.get('/api/data', (req, res) => {
// 获取数据的代码
const data = [/* 数据数组 */];
res.send(data);
});
通过以上两种方法,你可以将Axios的params返回的数据从对象转换为数组。