语法错误:意外的标识符'TypeIt'.导入调用只需要一个参数 [英] SyntaxError: Unexpected identifier 'TypeIt'. import call expects exactly one argument
本文介绍了语法错误:意外的标识符'TypeIt'.导入调用只需要一个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建我的第一个网站,并且尝试使用type it库.但是,每当我尝试将其导入到脚本文件中时,都会出现上述错误.到目前为止,这是我的代码:
I am creating my first website, and I am trying to use the type it library. However, whenever I try to import it into my script file, it gives me the above error. This is my code so far:
Index.html文件:
Index.html file:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<span id="element">Here is a string.</span>
</body>
<script src="script.js"></script>
</html>
script.js文件:
script.js file:
import TypeIt from 'typeit';
var instance = new TypeIt('#element', {
strings: ['This is my string!']
});
这是文件夹结构:
推荐答案
如果不使用任何模块捆绑程序,则需要在html文件之前添加以下标记:
If you are not using any module bundler then you need to add the following tag before your to your html file:
<script src="/node_modules/typeit/dist/typeit.min.js"></script>
此外,删除script.js文件中的import语句,并确保在加载script.js文件之前先加载typeit.min.js.
Also, remove the import statement in your script.js file and make sure that typeit.min.js is loaded before your script.js file.
这篇关于语法错误:意外的标识符'TypeIt'.导入调用只需要一个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文