Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/89.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何正确导入配置文件?_Javascript_Html_Jquery_Module_Config - Fatal编程技术网

Javascript 如何正确导入配置文件?

Javascript 如何正确导入配置文件?,javascript,html,jquery,module,config,Javascript,Html,Jquery,Module,Config,我正在学习导入/导出和模块。我能够导入jQuery文件,但在尝试导入配置文件时出错 是我得到的错误: config:1 Failed to load resource: the server responded with a status of 404 (Not Found) (我想使用一个配置文件,因为它将帮助我管理用于开发和生产的api令牌。) 我正在尝试将配置文件导入jquery文件: import config from './config' let weatherBaseUrl =

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

是我得到的错误:

config:1
Failed to load resource: the server responded with a status of 404 (Not Found)
(我想使用一个配置文件,因为它将帮助我管理用于开发和生产的api令牌。)

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

import config from './config'

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

...

export default function handleJquery() {
    $(handleExploreApp);
}
以下是配置文件中的内容:

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>

回购协议

(网页包对此有帮助吗?

试试这个

const-Config={
天气(API)端点:`https://api.weatherbit.io/v2.0/forecast/daily?`,
API_键:process.env.API_键,
} 

导出默认配置
try
WEATHER\u API\u ENDPOINT:'https://api.weatherbit.io/v2.0/forecast/daily?“,
with single quotes`是模板文本,谢谢,但我得到了相同的错误。