【问题标题】:Import/export module in JavaScriptJavaScript 中的导入/导出模块
【发布时间】:2020-06-12 17:56:44
【问题描述】:

index.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script src="./app.js"></script>
  </body>
</html>

app.js

import { hello } from './hello';

hello();

hello.js

export function hello() {
  console.log('Hello!');
}

未捕获的 SyntaxError:无法在模块 app.js:1 之外使用 import 语句

【问题讨论】:

    标签: javascript


    【解决方案1】:

    我认为您需要在脚本标签中添加类型:

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

    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Modules

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-08-21
    • 1970-01-01
    • 1970-01-01
    • 2022-12-17
    • 2021-07-18
    • 2020-07-18
    • 1970-01-01
    • 2017-06-29
    相关资源
    最近更新 更多