【(●—●)】ES6 模块module

模块引入,以下写法是否有错误??为什么没有弹框~~

index.html

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <h1></h1>
    <!-- <script type="module" src="./main.js"></script> -->
    <script type="module" src="./hello.js">
    </script>
</body>

</html>

hello.js

import * as hello from './sayHello';
hello.sayHello('Jack')

sayHello.js

export function sayHello(name) {
    alert(`Hello :${name}`);
}
阅读 2k
2 个回答

import * as hello from './sayHello.js';

hello.js 引入的路径要把后缀 .js 加上。

import * as hello from './sayHello.js';
hello.sayHello('Jack')
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题