-
add.js
const add = (x, y) => { return x + y; } export default add;
minus.js
const minus = (x, y) => { return x - y; } export default minus;
html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <script type="module"> import add from './module/add.js'; import minus from './module/minus.js'; console.log(add(4, 5)); console.log(minus(4, 5)); </script> </body> </html>
必须在服务器上打开页面才能正常运行,否则fiel协议会报跨域
借用http-server在服务器上打开就会正常运行
npx http-server
-