gpt4 book ai didi

javascript - javascript 中的 http 请求对象参数无法识别

转载 作者:行者123 更新时间:2023-12-02 22:44:49 26 4
gpt4 key购买 nike

我有这个 API 网址,我在 postman 中进行了测试并且它有效。

https://cdn.contentful.com/spaces/master/entries/?select=fields&content_type=events&fields.eventType=vue

如您所见,我有 fields.eventTypes 因为这是我必须根据 contentful 的文档来执行此操作的方式: https://www.contentful.com/developers/docs/concepts/relational-queries/

我的问题是,当我使用 axios 时,我想按如下方式传递 params 对象。

const CONTENTFUL_PARAMS = {
select: 'fields',
fields.eventType: 'vue', //js doesn't like this line
content_type: 'events',
};

我也尝试过

const CONTENTFUL_PARAMS = {
select: 'fields',
fields: {
eventType: 'vue' //got error 400 in the response
},
content_type: 'events',
};

我知道我可以将所有内容放入一个字符串中,然后进行字符串连接,但我不想这样做。如何在包含参数的对象中实现我想要做的事情。

return axios.get(BASE_URL, { params: CONTENTFUL_PARAMS });

最佳答案

就这样

const CONTENTFUL_PARAMS = {
select: 'fields',
"fields.eventType": 'vue',
content_type: 'events'
};

关于javascript - javascript 中的 http 请求对象参数无法识别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58454308/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com