如何在组件中引用 vendor 文件夹中的函数?
How do I reference a function in the vendor folder in a component?
我目前在组件的以下 JS 文件中收到 ES Lint 错误:
import Component from '@ember/component';
export default Component.extend({
didInsertElement() {
this.$(document).ready(function () {
App.init();
});
},
actions: {
toggleDropdownCurrentUser() {
this.toggleProperty('userDropDownOpen');
},
toggleNav() {
this.toggleProperty('navDropDownOpen');
}
}
});
App 函数报告为 not defined
。此功能在构建时编译的 vendorjs 文件中,绝对有效。
我尝试从 ../../../vendor/apps
导入应用程序,但我似乎无法获得正确的文件夹结构并以错误结束,提示我无法返回到项目的根目录。
我是否缺少某些方法?
我暂时假设 App
是全球性的。 Ember 的 .eslintrc.js
文件使用:
extends: 'eslint:recommended'
具有规则 no-undef
-> disallow the use of undeclared variables unless mentioned in /*global */ comments
好了,一个解决方案是将 /*global App*/
添加到每个引用 App
的文件的顶部。如果有很多地方,请使用 .eslintrc.js
选项:
globals: {
App: true
}
让App在任何地方都可以作为全局使用。
我目前在组件的以下 JS 文件中收到 ES Lint 错误:
import Component from '@ember/component';
export default Component.extend({
didInsertElement() {
this.$(document).ready(function () {
App.init();
});
},
actions: {
toggleDropdownCurrentUser() {
this.toggleProperty('userDropDownOpen');
},
toggleNav() {
this.toggleProperty('navDropDownOpen');
}
}
});
App 函数报告为 not defined
。此功能在构建时编译的 vendorjs 文件中,绝对有效。
我尝试从 ../../../vendor/apps
导入应用程序,但我似乎无法获得正确的文件夹结构并以错误结束,提示我无法返回到项目的根目录。
我是否缺少某些方法?
我暂时假设 App
是全球性的。 Ember 的 .eslintrc.js
文件使用:
extends: 'eslint:recommended'
具有规则 no-undef
-> disallow the use of undeclared variables unless mentioned in /*global */ comments
好了,一个解决方案是将 /*global App*/
添加到每个引用 App
的文件的顶部。如果有很多地方,请使用 .eslintrc.js
选项:
globals: {
App: true
}
让App在任何地方都可以作为全局使用。