【问题标题】:React error "./src/App.js Line 7: 'APIKEY' is assigned a value but never used no-unused-vars"反应错误“./src/App.js 第 7 行:'APIKEY' 被分配了一个值,但从未使用过 no-unused-vars”
【发布时间】: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;

【问题讨论】:

标签: javascript reactjs api


【解决方案1】:

您可以使用模板文字。 所以:

const api_call= await fetch(`http://api.openweathermap.org/data/2.5/forecast?id=524901&APPID=${APIKEY}`);

带有后缀和 $ 符号。

【讨论】:

    猜你喜欢
    • 2021-12-04
    • 1970-01-01
    • 2021-04-13
    • 2020-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-20
    • 2017-11-20
    相关资源
    最近更新 更多