相关疑难解决方法(0)

如何导入html中<script type ="module">标签中定义的es6模块?

我可以在我的html文件me.html中定义一个模块:

<script type="module" id="DEFAULT_MODULE">   
           import Atom from './atom.js';       
           console.log("definition of getAtom")
           export default function getAtom(){
            return new Atom('atom');
           }
           console.log("exported getAtom")
</script>
Run Code Online (Sandbox Code Playgroud)

另见

=>是否可以将"匿名"模块导入同一个html文件中的另一个模块脚本?或者某些"代码隐藏" - 也是由me.html文件加载的JavaScript文件?出口似乎有效; 至少它不会抛出任何错误.

为了导入getAtom我试过的方法,例如:

<script type="module">
    import getAtom from '.'; //this line does not work
    console.log("usage of getAtom")
    var atom = getAtom();             
</script>
Run Code Online (Sandbox Code Playgroud)

我希望有一些语法

 import getAtom;
 import getAtom from '.';
 import getAtom from window;
 import getAtom from './me.html';
 import getAtom from '.DEFAULT_MODULE';
Run Code Online (Sandbox Code Playgroud)

但是,这些线都不起作用.

=>如果可能的话,引用"匿名"模块的正确语法是什么?

我使用Chrome版本63.0.3239.108.

相关问题:

如何动态执行/评估包含ES6模块的JavaScript代码/需要一些依赖项?

html javascript es6-modules

5
推荐指数
1
解决办法
1215
查看次数

标签 统计

es6-modules ×1

html ×1

javascript ×1