【问题标题】:Error in finding the config variable while running the app运行应用程序时查找配置变量时出错
【发布时间】:2019-01-04 07:32:34
【问题描述】:

我在搜索位置时遇到错误它显示找不到变量配置。任何帮助将不胜感激。

【问题讨论】:

    标签: reactjs react-native npm


    【解决方案1】:

    如果您查看代码,在App.js 第 20 行中会看到:

    import config from './config';`
    

    然后它稍后在第 84 行使用该导入:

    axios.get(`https://api.wunderground.com/api/${config.apiKey}/geolookup/q/${this.state.latitude},${this.state.longitude}.json`)
    

    由于 repo 中没有 config.js 文件,看来这是一个您需要自己创建的文件来存储应用程序机密,所以没有签入是一件好事,因为您不希望其他人知道您的机密.

    如果你想变得非常棒,你可以针对那个 repo 创建一个 PR,在 README 中解释需要做什么,这样其他使用该代码的人就不会遇到同样的问题 :)

    【讨论】:

    • 我需要生成 apikeys。
    • 我必须把它放在“axios.get(https://api.wunderground.com/api/${config.apiKey}/geolookup/q/${this.state.latitude},${this.state.longitude}.json)”中
    • apikeys 写在哪里?
    【解决方案2】:

    配置文件丢失。

    您需要创建自己的配置文件,其中包含您将从Wunderground's API 收到的 API 密钥。

    【讨论】:

    • 如何从那里找到 api?
    • 不幸的是,您可以在这里看到api.wunderground.com/weather/api Wunderground 不再提供免费的天气 API 密钥。您将不得不选择另一个天气 API 提供商,例如 openweathermap.org/api
    • 我也添加了新的 api,即“axios.get(https://samples.openweathermap.org/data/2.5/forecast?q=M%C3%BCnchen,DE&appid=b6907d289e10d714a6e88b30761fae22)”
    • 找不到变量:配置
    • 检查配置的导入位置并替换
    猜你喜欢
    • 2021-08-11
    • 1970-01-01
    • 2018-10-03
    • 1970-01-01
    • 2012-04-02
    • 2016-10-07
    • 2014-01-10
    • 2014-10-09
    • 2019-01-18
    相关资源
    最近更新 更多