Javascript GET API_Link net::ERR_失败--------未捕获(承诺中)类型错误:未能获取

Javascript GET API_Link net::ERR_失败--------未捕获(承诺中)类型错误:未能获取,javascript,reactjs,fetch,Javascript,Reactjs,Fetch,我正在尝试从openweathermap.org获取API,但仍然收到错误: 获取API\u链接网络::错误\u失败 未捕获(承诺中)类型错误:无法获取 这是我的密码: import React, { useState } from 'react'; import Form from './components/form' import Forecast from './components/forecast' const App = (props) => { const

我正在尝试从openweathermap.org获取API,但仍然收到错误:

  • 获取API\u链接网络::错误\u失败
  • 未捕获(承诺中)类型错误:无法获取
这是我的密码:

import React, { useState } from 'react';
import Form from './components/form'
import Forecast from './components/forecast'




const App = (props) => {
  const api_key = 'b6907d289e10d714a6e88b30761fae22';
  const [error, setError] = useState("")
  const [temperature, setTemperature] = useState("")
  const [humidity, setHumidity] = useState("")
  const [city, setCity] = useState("")


const getWeather = async (e) => {
  console.log('jj')
  const city = e.target.elements.city.value;
  e.preventDefault();
  const api_call = await fetch(`https://samples.openweathermap.org/data/2.5/weather?q=${city}&appid=${api_key}`);
  const response = await api_call.json();
  console.log('jj')
  if(city){
    setTemperature(response.main.temp)
    setHumidity(response.main.humidity)
    setCity(response.name)
  }else{
    setError('please fill out input error')
  }

}
return (
  <div>
<Form loadWeather={getWeather}/>
<Forecast 
temperature={temperature}
humidity={humidity}
city={city}
error = {error}/>
  </div>
)
}
import React,{useState}来自“React”;
从“./components/Form”导入表单
从“./components/Forecast”导入预测
常量应用=(道具)=>{
常数api_键='b6907d289e10d714a6e88b30761fae22';
常量[error,setError]=useState(“”)
常数[温度,设定温度]=使用状态(“”)
常数[湿度,设置湿度]=使用状态(“”)
const[city,setCity]=useState(“”)
const getWeather=async(e)=>{
console.log('jj')
const city=e.target.elements.city.value;
e、 预防默认值();
const api_call=等待获取(`https://samples.openweathermap.org/data/2.5/weather?q=${city}&appid=${api_key}`);
const response=wait api_call.json();
console.log('jj')
国际单项体育联合会(城市){
设定温度(响应主温度)
设置湿度(响应主湿度)
setCity(response.name)
}否则{
setError('请填写输入错误')
}
}
返回(
)
}

我用其他API做的,没有问题

在try-catch块中使用wait-fetch,然后根据浏览器开发工具(最好是chrome)中的错误消息look解决错误。有一个网络选项卡可以为您提供有关错误的更多信息,还有控制台选项卡。我猜这将是一场灾难