我用教程中的React.js创建了一个天气应用程序,现在我陷入了困境,无法解决这个错误,。如何纠正此错误?
下面是我的代码:
import React from 'react';
import './App.css';
import Titles from './components/titles';
import Form from './components/form';
import Weather from './components/weather';
const APIKEY = "0bfdbb5c40aa44b13478951b236a0625";
class WeatherApp extends React.Component {
getWeather = async (e) => {
e.preventDefault();
const api_call= await fetch('http://api.openweathermap.org/data/2.5/forecast?id=524901&APPID={APIKEY}');
const response = await api_call.json();
console.log(response);
}
render() {
return (
<div>
<Titles/>
<Form loadWeather={this.getWeather} />
<Weather/>
</div>
)
}
}
export default WeatherApp;
发布于 2018-10-14 10:26:45
您可以使用模板文本。因此:
const api_call= await fetch(`http://api.openweathermap.org/data/2.5/forecast?id=524901&APPID=${APIKEY}`);
带着背景文件和标牌。
https://stackoverflow.com/questions/52801595
复制相似问题