如何解决导入和导出问题Javascript无node.js
你好!
我第一次尝试使用导入/导出,但是我的代码中存在此问题:
The requested module '../Ajout/script.js' does not provide an export named 'flagMap'
我有这些文件Supprimer.js,包含在第一行:
import{flagMap,findUrl,createUrl,texteValide} from '../Ajout/script.js';
并在父文件夹的另一个forlder中包含的Ajout.js中:
var flagMap={/*really long map*/}
function findUrl(isoCode){/*long url finder*/}
function createUrl(svgUrl) {
return `https://upload.wikimedia.org/wikipedia/${svgUrl}`;
}
function texteValide(element){/*text validation for a form*/}
export{flagMap,texteValide};
/*
other non-exported functions
*/
当我导入脚本时,我的html中有type =“ module”,而我的Ajout.js也包含其他功能,可能是引起问题了吗?
另外:问题不仅是flagMap,而且是每个导入,因为如果我从导入中删除flagMap,它会显示另一个文件
解决方法
这对我来说很好:
fun
<!-- index.html -->
<html>
<head> ... </head>
<body>
<script type="module" src="path/to/Supprimer.js"></script>
</body>
</html>
// Ajout.js
var flagMap = {
// ...
};
function findUrl(isoCode) {
// ...
}
function createUrl(svgUrl) {
// ...
}
function textValide(element) {
// ...
}
// Export functions and variables
export {
flagMap,findUrl,createUrl,texteValide
};
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。