繁体   English   中英

如何正确导入配置文件?

[英]How can I import the config file properly?

我正在研究导入/导出和模块。 我能够导入 jQuery 文件,但在尝试导入配置文件时出现错误。

是我得到的错误:

config:1
Failed to load resource: the server responded with a status of 404 (Not Found)

(我想使用配置文件,因为它可以帮助我管理用于开发和生产的 api 令牌。)

我正在尝试将配置文件导入 jquery 文件:

以下是配置文件中的内容:

export default {
    WEATHER_API_ENDPOINT: `https://api.weatherbit.io/v2.0/forecast/daily?`,
    API_KEY: process.env.API_KEY,
  }

这是 jquery 文件的一部分:

import config from './config'

let weatherBaseUrl = config.WEATHER_API_ENDPOINT;
let weatherApiKey = config.API_KEY;

...

export default function handleJquery() {
    $(handleExploreApp);
}

以下是主文件中的内容:

import handleJquery from './jquery.js'

handleJquery()

主文件链接到 html 文件中,如下所示:

  <script type="module" src="main.js"></script>

这是回购的链接

(webpack 会对此有所帮助吗?)

尝试这个

 const Config = { WEATHER_API_ENDPOINT: `https://api.weatherbit.io/v2.0/forecast/daily?`, API_KEY: process.env.API_KEY, } export default Config

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM