Using ES6 Module In Browser.

 

Now in browser, to use comman js module style:

 

1. i1.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 type="module">
      import x from "./i1.js";
      console.log(x.a);
    </script>
  </body>
</html>

2. i1.js in same level folder

export default { a: "2" };

 

This makes js module imprting exports from a single file as a module via common js style possible.

posted @ 2026-01-25 09:39  calochCN  阅读(0)  评论(0)    收藏  举报