【发布时间】:2019-10-18 15:51:12
【问题描述】:
我有这个 API url,我在 postman 中测试过,它可以工作。
如您所见,我有 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',
};
我知道我可以将所有内容放在一个字符串中并执行 string concat put 我不想那样做。如何在包含参数的对象中实现我想要做的事情。
return axios.get(BASE_URL, { params: CONTENTFUL_PARAMS });
【问题讨论】:
-
您在
fields.eventType和fields: {}中缺少,。 -
@ÖmürcanCengiz 抱歉,我正在编辑此页面内的参数。实际上,我的真实代码中有逗号,但仍然不起作用:(
标签: javascript axios httprequest contentful