因此,我最近开始使用Axios创建我的第一个项目。当我尝试从API提取数据时,默认情况下(我认为),axios给我提供如下URL:
/search?health[]=alcohol-free&health[]=celery-free&nutrient[]=calcium&nutrient[]=carbs
但是API(Edamam API)需要:
/search?health=alcohol-free&health=celery-free&nutrients%5BCA%5D=100-&nutrients%5BFAT%5D=100
我的参数:
const params = {
...other,
health: ["alcohol-free", "celery-free"],
nutrient: {
CA: "100-200",
FAT: "100" // under 100mg
},
}
我该如何更正我的网址。我不知道在axios中修复URL的位置。谢谢!
在调用qs
之前,使用axios
包对您的请求进行字符串化处理>
const qs = require('qs')
const params = {
...other,
health: ["alcohol-free", "celery-free"],
nutrient: {
CA: "100-200",
FAT: "100" // under 100mg
},
}
axios(qs.stringify(params))