相关疑难解决方法(0)

ES6模块:导入后未定义的onclick功能

我正在测试ES6模块,并希望让用户使用onclick以下方法访问一些导入的函数:

的test.html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>Module Test</title>
</head>
<body>
    <input type="button" value="click me" onclick="hello();"/>
    <script type="module">import {hello} from "./test.js";</script>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

test.js:

export function hello() {console.log("hello");}
Run Code Online (Sandbox Code Playgroud)

当我单击按钮时,开发人员控制台会说:ReferenceError:未定义hello.如何从模块导入函数,以便它们可用作onclick函数?

我正在使用Firefox 54.0 dom.moduleScripts.enabled设置为true.

javascript ecmascript-6 es6-modules

22
推荐指数
3
解决办法
7155
查看次数

标签 统计

ecmascript-6 ×1

es6-modules ×1

javascript ×1