【发布时间】:2018-10-14 10:09:01
【问题描述】:
我用教程中的 React.js 创建了一个天气应用程序,现在我卡住了,无法解决这个错误 "./src/App.js 第 7 行:'APIKEY' 被分配了一个值,但从来没有使用 no-unused-vars"。我该如何解决这个错误?
下面是我的代码:
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;
【问题讨论】:
-
更改这一行 const api_call= await fetch('api.openweathermap.org/data/2.5/forecast?id=524901&APPID={APIKEY}');有了这个 const api_call= await fetch(
http://api.openweathermap.org/data/2.5/forecast?id=524901&APPID=${APIKEY});
标签: javascript reactjs api