[英]React error “./src/App.js Line 7: 'APIKEY' is assigned a value but never used no-unused-vars”
I create a weather app with React.js from tutorial and now I'm stuck and can't solve this error "./src/App.js Line 7: 'APIKEY' is assigned a value but never used no-unused-vars" . 我从教程中使用React.js创建了一个天气应用,现在我陷入了困境,无法解决此错误“。/src/App.js第7行:'APIKEY'被分配了一个值,但从未使用过no-unused-vars “ 。 How can I fix this error?
如何解决此错误?
Below is my code: 下面是我的代码:
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;
You can use the template literals. 您可以使用模板文字。 So :
因此:
const api_call= await fetch(`http://api.openweathermap.org/data/2.5/forecast?id=524901&APPID=${APIKEY}`);
With the backtites and the $ sign. 带有背景色和$符号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.