gpt4 book ai didi

javascript - system.js 从另一个文件夹导入

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:16:05 31 4
gpt4 key购买 nike

我有 public/index.htmlsrc/app.js .

内部index.html我有以下 system.js来电加载app.js

<script>System.import('../src/app');</script>

失败并出现以下错误:

GET https://registry.jspm.io/src/app.js 404 (Not Found)

从另一个文件夹加载文件的语法应该是什么?

最佳答案

您可能忘记了其他一些事情:

1) 您必须导入 system.js(使用 jspm init 自动安装)

2) 你必须包含你的config.js(用jspm init自动安装)

        <script src="../jspm_packages/system.js"></script>

<script src="../config.js"></script>

<script>
System.import('client/index').catch(console.log.bind(console));
</script>

3) 查看我的导入如何显示“客户端/索引”,这意味着我的文件夹结构如下所示:

enter image description here

4) 最后,config.js 有了基本路径(这是您的 system.import 开始的地方;不管 index.html 文件在哪里。)

System.config({
"baseURL": "/",
"transpiler": "traceur",
"paths": {
"*": "*.js",
"github:*": "jspm_packages/github/*.js",
"npm:*": "jspm_packages/npm/*.js"
}
});

其中一个应该可以解决所有问题。我认为它是#2

关于javascript - system.js 从另一个文件夹导入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30610244/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com