Reactjs 当我插入${city}、${country}以在开放天气API上查询天气时,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
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>
)