在用ES6的 import引入模块时,控制台显示错误:Uncaught SyntaxError: Cannot use import statement outside a module
Uncaught SyntaxError: Cannot use import statement outside a module-QUI-Notes

错误原因:

从报错信息中获知:无法在模块外部使用 import语句。
模块化(Module)的加载是用 ES6语法实现的,HTML网页引用时,需要在 script标签内加入 type="module"属性。

解决方法:

在<script> 标签内添加  type="module" 属性。

<script type="module" src="./js/index.js"></script>