【发布时间】:2020-08-31 13:48:18
【问题描述】:
好的,所以当我使用 ComponentDidUpdate() 时,get 调用工作得很好,除了它无限循环的事实。当我使用此代码时:
componentDidMount() {
const getRequest = async() => {
try {
const result = await axios.get(`https://api.openweathermap.org/data/2.5/onecall?lat=${this.state.lat}&lon=${this.state.long}&
exclude={part}&appid=${this.state.apikey}&units=imperial`);
console.log(result);
}
catch(err){
console.error(err);
}
}
getRequest();
}
我不断收到 400 错误。谁能帮我解决这个问题,我迷路了。这是一个个人项目,在任何人询问之前都不是家庭作业。
【问题讨论】:
-
你的控制台输出什么?有什么错误吗?还有,不应该是
exclude=${part}吗? -
400 表示错误请求。需要更多信息来回答这个问题。
-
您应该检查开发者控制台的网络部分以查看您发送到服务器的请求。可能您的某些变量未定义,这就是您从服务器收到错误请求的原因。
标签: javascript reactjs axios