I have a flask app with the following file located in static/js/foo.js :(我有一个flask应用程序,其中以下文件位于static / js / foo.js中 :)
export default class Foo {
constructor(message) {
this.message = message;
}
toString() {
return `${this.message}`;
}
}
In my templates/index.html file, I'm trying to create an instance of Foo
as follows:(在我的templates / index.html文件中,我尝试如下创建Foo
的实例:)
<script src="{{ url_for('static', filename='js/foo.js') }}" type="module"></script>
<script>
let foo = new Foo('hello foo!');
console.log(`${foo}`);
</script>
However, I'm getting the following error in the console: Uncaught ReferenceError: Foo is not defined .(但是,我在控制台中收到以下错误: Uncaught ReferenceError:Foo未定义 。)
Is there a simple way to use a class defined in another file, ie Foo
from within foo.js ?(有没有简单的方法可以使用在另一个文件(即foo.js中的 Foo
定义的类?)
ask by alex_lewis translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…