首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >反应错误“。/src/App.js第7行:”每个键“被分配一个值,但从不使用未使用的-vars”。

反应错误“。/src/App.js第7行:”每个键“被分配一个值,但从不使用未使用的-vars”。
EN

Stack Overflow用户
提问于 2018-10-14 10:09:01
回答 1查看 263关注 0票数 0

我用教程中的React.js创建了一个天气应用程序,现在我陷入了困境,无法解决这个错误,。如何纠正此错误?

下面是我的代码:

代码语言:javascript
运行
复制
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;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-10-14 10:26:45

您可以使用模板文本。因此:

代码语言:javascript
运行
复制
const api_call= await fetch(`http://api.openweathermap.org/data/2.5/forecast?id=524901&APPID=${APIKEY}`);

带着背景文件和标牌。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52801595

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档