Fetch API在localhost上运行良好,但在Heroku上却无法运行

时间:2019-12-28 19:51:45

标签: reactjs github heroku fetch

我在React.js APP中有一个使用openWeather API的Fetch API,该提取在localhost上工作正常,但是在我将代码上传到GITHUB并将其部署到Heroku之后,当我使用API​​请求按钮时应用崩溃了,并且给出此错误:

未处理的拒绝(TypeError):不允许请求资源 (匿名功能) src / App.js:89   86 | const country = e.target.elements.country.value   87 |   88 |如果(城市和国家){

  

89 | const api_call =等待fetch(http://api.openweathermap.org/data/2.5/weather?q=${city},${country}&appid=${Api_key}        | ^ 90 | const response = await api_call.json();     91 | this.setState({     92 |城市:${response.name},${response.sys.country}

有人可以帮助我解决此问题吗?

0 个答案:

没有答案