简体   繁体   English

反应错误“ ./src/App.js第7行:'APIKEY'被分配了一个值,但从未使用过no-unused-vars”

[英]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.

相关问题 Vue.js 错误“app' is assigned a value but never used no-unused-vars - Vue.js error "app' is assigned a value but never used no-unused-vars src\\App.js &#39;nav&#39; 已定义但从未使用过 no-unused-vars - src\App.js 'nav' is defined but never used no-unused-vars 11:5 错误“路由器”被分配了一个值,但从未使用过 no-unused-vars - 11:5 error 'router' is assigned a value but never used no-unused-vars react.js 'x' 被分配了一个值,但从未使用过 no-unused-vars - react.js 'x' is assigned a value but never used no-unused-vars &#39;inStock&#39; 被赋值但从未使用过 no-unused-vars - 'inStock' is assigned a value but never used no-unused-vars [eslint] src\App.js 第 2:8 行中的 React js 错误警告:'person' 已定义但从未使用过 - React js error WARNING in [eslint] src\App.js Line 2:8: 'person' is defined but never used 组件已定义但从未使用 reactjs 中的 no-unused-vars 错误警告 - component is defined but never used no-unused-vars error warning in reactjs 定义了“ stringValues”,但从未使用过no-unused-vars - “stringValues” is defined but never used no-unused-vars 定义了“标头”,但从未使用过未使用的变量 - 'Header' is defined but never used no-unused-vars &#39;Home&#39; 已定义但从未使用 no-unused-vars&quot;.* - 'Home' is defined but never used no-unused-vars".*
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM