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

http request object params in javascript not recognized

我有这个 API url,我已经在 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 时,我想按如下方式传递参数对象。

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'
};