简体   繁体   English

在svelte中导入javascript文件

[英]Import javascript file in svelte

So today I discovered Svelte and I absolutley love the concept. 所以今天我发现了Svelte和我绝对喜欢这个概念。 I only got one problem I wrote a small helper.js file and can't seem to import it. 我只有一个问题,我写了一个小的helper.js文件,似乎无法导入它。 Every time I try to reference the class I get 每次我尝试引用我得到的课程

ReferenceError: Helper is not defined ReferenceError:未定义助手


main.js file: main.js文件:

import App from './App.svelte';
import './helper.js';

var app = new App({
    target: document.body
});
export default app;


App.svelte file: App.svelte文件:

<script>
    let helper = new Helper();
</script>

<h1>Hello</h1>


helper.js file: 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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM