在svelte中导入javascript文件 [英] Import javascript file in svelte
本文介绍了在svelte中导入javascript文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以今天我发现 Svelte ,我绝对喜欢这个概念.我只遇到一个问题,我写了一个小的 helper.js 文件,但似乎无法导入它.每次我尝试引用我得到的课程
So today I discovered Svelte and I absolutley love the concept. I only got one problem I wrote a small helper.js file and can't seem to import it. Every time I try to reference the class I get
ReferenceError:未定义助手
ReferenceError: Helper is not defined
main.js文件:
import App from './App.svelte';
import './helper.js';
var app = new App({
target: document.body
});
export default app;
App.svelte文件:
<script>
let helper = new Helper();
</script>
<h1>Hello</h1>
helper.js文件:
class Helper {
constructor() {
console.log("working");
}
}
推荐答案
您需要将其导入到使用它的文件中:
You need to import it into the file that uses it:
<script>
import Helper from './helper.js';
let helper = new Helper();
</script>
<h1>Hello</h1>
这篇关于在svelte中导入javascript文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文