Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs 当我插入${city}、${country}以在开放天气API上查询天气时,API回调就不起作用_Reactjs_Api_Asynchronous_Async Await_Openweathermap - Fatal编程技术网

Reactjs 当我插入${city}、${country}以在开放天气API上查询天气时,API回调就不起作用

Reactjs 当我插入${city}、${country}以在开放天气API上查询天气时,API回调就不起作用,reactjs,api,asynchronous,async-await,openweathermap,Reactjs,Api,Asynchronous,Async Await,Openweathermap,这是我的api调用——收到的错误是值未定义,可能是指我的城市和国家变量??帮忙 goGetWeather = async e => { e.preventDefault() const city = e.target.elements.city.value const country = e.target.elements.country.value const api_call = await fetch( `http://api.open

这是我的api调用——收到的错误是值未定义,可能是指我的城市和国家变量??帮忙

    goGetWeather = async e => {
    e.preventDefault()
    const city = e.target.elements.city.value
    const country = e.target.elements.country.value
    const api_call = await fetch(
    `http://api.openweathermap.org/data/2.5/weather? 
    q=${city},${country}&appid=8004ed6a9e53c30dd054d07
    9fff7f24e&un 
    its=metric`
    )
    const data = await api_call.json()
    console.log(data)

    <Weather
      city={this.state.city}
      country={this.state.country}
      description={this.state.description}
    />
    <br />
  </div>
)
render(){ 返回(

    <Weather
      city={this.state.city}
      country={this.state.country}
      description={this.state.description}
    />
    <br />
  </div>
)

我从childcomponent中的输入中删除了表单控件属性--现在可以工作了

嗨,阿米尔,很抱歉刚刚注意到你的帖子-->是的,经过长时间的凝视,我意识到我在childcomponent中的输入上有表单控件属性…现在工作得很好..但我确实需要学习如何更好地保存;)
    <Weather
      city={this.state.city}
      country={this.state.country}
      description={this.state.description}
    />
    <br />
  </div>
)