简体   繁体   English

如何使用axios在get请求中传递参数?

[英]How to pass parameters in get request using axios?

I am trying to pass api_key in the get request parameter using axios 我试图使用axios在get请求参数中传递api_key

here is my code 这是我的代码

const instance = axios.create({
  baseURL: "https://api.themoviedb.org/3"
});
export function crudify(path) {
  function get(id) {
    return instance.get(`${path}/${id}`, {
      params: {
        api_key: "qwerasd"
      }
    });
  }

  return { get };
}

I expected to get the URL: 我希望得到这个网址:

https://api.themoviedb.org/3/genre/movie/list?api_key=qwerasd https://api.themoviedb.org/3/genre/movie/list?api_key=qwerasd

but instead I get: 但相反,我得到:

https://api.themoviedb.org/3/genre/movie/list https://api.themoviedb.org/3/genre/movie/list

You need to append query string params directly to url: 您需要将查询字符串params直接附加到url:

function get(id) {
    return instance.get(`${path}/${id}?api_key=qwerasd`);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM