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

**URL:** <https://meta.discourse.org/t/showing-different-content-for-mobile-view-in-a-gjs-file/374657>\
**Category:** Development\
**Tags:** mobile, ember\
**Created:** [2025年七月17日 15:39 UTC](https://meta.discourse.org/t/showing-different-content-for-mobile-view-in-a-gjs-file/374657 "2025-07-17T15:39:55Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![Alteras](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/alteras/32/179824_2.png) [@Alteras](https://meta.discourse.org/u/Alteras)\
**Post date:** [2025年七月17日 16:22 UTC](https://meta.discourse.org/t/showing-different-content-for-mobile-view-in-a-gjs-file/374657/2 "2025-07-17T16:22:55Z")

</div>

哦，可能只需要手动导入 `site` 服务。

```jsx
import { apiInitializer } from "discourse/lib/api";

export default apiInitializer("1.8.0", (api) => {
  const site = api.container.lookup("service:site");
  api.renderInOutlet(
    "composer-after-save-or-cancel",
    <>
      {{#if site.mobileView}}
      Mobile!
      {{else}}
      Normal!
      {{/if}}
    </>
  );
});

```

---

_[View the full topic](https://meta.discourse.org/t/showing-different-content-for-mobile-view-in-a-gjs-file/374657)._
