我通常在创建主题组件时需要查找各种导入,因此我决定将它们汇总并放在这里。
与 Ember 相关
| 名称 | 导入 | 用法 |
|---|---|---|
| Component | import Component from \"@glimmer/component\"; |
export default class MyComponentClass extends Component {} |
| Action decorator | import { action } from \"@ember/action\"; |
@action |
| Tracked decorator | import { tracked } from \"@glimmer/tracking\"; |
@tracked myTrackedVar |
| Service decorator | import { service } from \"@ember/service\"; |
@service modal |
| (Glimmer 模板) on | import { on } from \"@ember/modifier\"; |
\u003cp {{on \"click\" this.someAction}}\u003eClick me!\u003c/p\u003e[1] |
与 Discourse 相关
| 名称 | 导入 | 用法 |
|---|---|---|
| apiInitializer | import { apiInitializer } from \"discourse/lib/api\"; |
export default apiInitializer((api) =\u003e {}) |
| withPluginApi | import { withPluginApi } from \"discourse/lib/plugin-api\"; |
withPluginApi((api) =\u003e {})[2][3] |
| ConditionalLoadingSpinner | import ConditionalLoadingSpinner from \"discourse/components/conditional-loading-spinner\"; |
\u003cConditionalLoadingSpinner @condition={{this.loading}} /\u003e |
| DButton | import DButton from \"discourse/components/d-button\"; |
\u003cDButton @icon=\"...\" @action={{this.someAction}} /\u003e |
| ajax | import { ajax } from \"discourse/lib/ajax\"; |
ajax(\"/path/here\")[4] |
| i18n | import { i18n } from \"discourse-i18n\"; |
{{i18n \"locale_key\"}}[5] |
| (Glimmer 模板) Equals, not equals, greater than, greater than or equals, less than, less than or equals, or, not, and, has, includes | import { eq, and, ... } from \"truth-helpers\"; |
{{#if (eq this.something this.something2)}}[6] |
您可能会看到它们被组合使用,例如 ConditionalLoadingSpinner 的条件为跟踪变量,或者 DButton 的操作等。
希望这有帮助!
\u003csmall\u003e我不是专家,所以如果您发现任何不准确之处,请帮助更正或提出,谢谢
。\u003c/small\u003e
您也可以使用
input、mousedown、focusin等事件 ↩︎请参阅 discourse/app/assets/javascripts/discourse/app/instance-initializers/enable-emoji.js at 99ace1be120b928f6c694d0118959d745cc4bdbe · discourse/discourse · GitHub ↩︎
我认为建议使用
apiInitializer;我认为这是旧版本? ↩︎工作方式类似于
fetch()。将其放入async函数中,并带有await关键字。 ↩︎如果您从核心存储库获取区域设置,例如 user.summary.stats ↩︎
像
and和or这样的参数可以有 2 个以上 ↩︎