【发布时间】:2019-11-16 13:21:43
【问题描述】:
我在导入/导出类时遇到问题。它似乎很受欢迎。有时它会起作用,有时它不会。
我收到以下控制台错误: Uncaught ReferenceError: test is not defined at main.js:
我已经在网上上传了这个测试http://tibbotts.epizy.com/testClassImport/index.html
我尝试将“./test.js”更改为“/test.js”、“./test”等。
我尝试在网上搜索解决方案,但所有解决方案都针对 script type="module" ... fix。
<!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 并导入脚本,但我却收到以下错误消息:未捕获的 ReferenceError: test is not defined at main.js:
【问题讨论】:
标签: javascript class ecmascript-6 import referenceerror