簡體   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”

我從教程中使用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(`http://api.openweathermap.org/data/2.5/forecast?id=524901&APPID=${APIKEY}`);

帶有背景色和$符號。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM