无法导入 JavaScript class 文件
Unable to import a JavaScript class file
我在 JavaScript 中有这个 class 文件,我把它放在一个表单文件夹中:
export class FormRegTest {
constructor(payload) {
this.payload = payload;
}
}
我已经将它导入到根 index.js
文件中,如下所示:
import { FormRegTest } from './forms/FormRegTest';
然后在 index.js
中创建了它的实例,如下所示:
const formTest = new FormRegTest(payload);
在我的 app.html
中,我包含了 index.js
文件,如下所示:
<script type="module" src="index.js"></script>
但在控制台中我继续收到以下错误:
Failed to load resource: the server responded with a status of 404 (Not Found)
如果无法加载 ./forms/FormRegTest
,请尝试包含 .js
文件扩展名。一些 IDE 不包含扩展是常见问题。
我在 JavaScript 中有这个 class 文件,我把它放在一个表单文件夹中:
export class FormRegTest {
constructor(payload) {
this.payload = payload;
}
}
我已经将它导入到根 index.js
文件中,如下所示:
import { FormRegTest } from './forms/FormRegTest';
然后在 index.js
中创建了它的实例,如下所示:
const formTest = new FormRegTest(payload);
在我的 app.html
中,我包含了 index.js
文件,如下所示:
<script type="module" src="index.js"></script>
但在控制台中我继续收到以下错误:
Failed to load resource: the server responded with a status of 404 (Not Found)
如果无法加载 ./forms/FormRegTest
,请尝试包含 .js
文件扩展名。一些 IDE 不包含扩展是常见问题。