哪里出问题了(module)
来源:2-4 【避坑】常见问题集锦
localhost999
2021-10-20 18:09:57
index2
<!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{num1,num2} from './index1.html';
import{add} from './index.html';
console(add(num1,num2));
</script>
</body>
</html>index
<!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">
function add(add1,add2){
return add1+add2;
}
export{add};
</script>
</body>
</html>index1
<!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">
const num1=1;
const num2=2;
export{num1,num2};
</script>
</body>
</html>1回答
同学你好,“声明、导出模块的代码”需要写在js文件中,不能写在html文件中。同学的将其写在了html文件中:

即html文件中,需要从js文件中导入模块:

同学从html文件中,导入模块了,所以出问题了:

祝学习愉快!
相似问题