我正在尝试用react和axios做一个get请求。我在我正在使用的packages.json中配置了一个代理,并根据点击的按钮更改网站url。当我最后尝试用axios做一个get请求时,它没有像往常一样使用代理,而只是将get url添加到浏览器中现有的url中。
你知道少了什么吗?还是错了?
package.json:
...
"proxy": "http://localhost:5000"
...
代码:
export const createUserIfNotExists = user => dispatch => {
axios.get(`api/user/${user.id}`).then(res => { // => dispatch =>
console.log('in createUserIfNotExists response')
...
例如,如果我的站点中的url是:"https://localhost:3000/search/asd/2/3/asdas“,那么它只会向"https://localhost:3000/search/asd/2/3/api/user/10216805034506570”而不是"https://localhost:3000/api/user/10216805034506570“发送get请求。
我想像以前一样使用axios,我遗漏了什么?
发布于 2019-05-10 03:49:41
您的url中缺少'/‘。
尝试使用axios.get(/api/user/${user.id}
而不是axios.get(api/user/${user.id}
https://stackoverflow.com/questions/56066411
复制相似问题