我在导入/导出课程时遇到问题。看来如此命中注定。有时它在其他时间无法使用。
我收到以下控制台错误: 未被捕获的ReferenceError:main.js中未定义测试:
我已经在线http://tibbotts.epizy.com/testClassImport/index.html上上传了该测试
我尝试将“ ./test.js”更改为“ /test.js”、“./test”等。
我曾尝试在网上搜索解决方案,但所有解决方案都针对脚本type =“ module” ...修复程序。
<!DOCTYPE html>
<html>
<head>
<title>Test Class Importing</title>
<script type="module" src="main.js"></script>
</head>
<body>
hello this is a test
</body>
</html>
import Test from "./test.js";
test = new Test();
test.speak();
export default class Test{
constructor(test){
this._test = `Test is Successful`;
}
speak(){
console.log(this._test);
}
}
我希望它能够控制台Test is Successful
控制台并导入脚本,但是却收到以下错误消息:Uncaught ReferenceError:main.js上未定义测试:
答案 0 :(得分:0)
您可能希望使用test
或var
之类的关键字来初始化let
:
let test = new Test();
也不要忘记您的构造函数需要一个参数:
let test = new Test("something");