在 .gjs 文件中为移动视图显示不同内容

如果你愿意,可以将整个类放在 renderInOutlet 调用中:

import { apiInitializer } from "discourse/lib/api";
import Component from "@glimmer/component";
import { service } from "@ember/service";

export default apiInitializer((api) => {
  api.renderInOutlet(
    "composer-after-save-or-cancel",
    class extends Component {
      @service site;

      <template>
        {{#if this.site.mobileView}}
          Mobile!
        {{else}}
          Normal!
        {{/if}}
      </template>
    }
  );
});

.lookup() 解决方案也是合理的——这正是 @service 在后台所做的 :ok_hand:

6 个赞