http://codepen.io/beckbeach/pen/mWqrep我codepen陣營不會通過道具API鏈接
陣營不會在我的API鏈接道具傳遞到$ {} this.state.query。我究竟做錯了什麼?
class App extends React.Component {
constructor(props) {
super(props)
this.state = {
query: ''
}
}
searchFunction() {
fetch('http://api.openweathermap.org/data/2.5/weather?zip=${this.state.query},us&appid=748f643131acee33c207bee1a969f6e3', {
method: 'GET'
}).then((res) => {
res.json().then((data) => {
console.log(data);
})
})
.catch((err) => {
console.log(err);
})
}
render() {
return (
<div>
<h1>Check The Weather!</h1>
<div>
<input type="text" placeholder="Enter Zipcode" value={this.state.query} onChange={event => {this.setState({query: event.target.value})}} />
<button type="submit" onClick={() => this.searchFunction()}>CHECK WEATHER </button>
</div>
</div>
)}
}
ReactDOM.render(<App/>, document.getElementById('root'))
FWIW,這無關與之反應本身。您沒有正確使用模板文字。 –