【问题标题】:Ionic 5 force light mode for certain page某些页面的 Ionic 5 强制光模式
【发布时间】:2021-03-12 10:56:01
【问题描述】:

希望仅针对某些页面关闭深色模式。

参考Ionic documentation,下面的方法不起作用,文档正文中没有显示暗类。

document.body.classList.toggle('dark', false);

有什么解决办法吗? 谢谢。

【问题讨论】:

    标签: ionic-framework ionic5


    【解决方案1】:

    应该可以这样做

    document.body.classList.toggle('dark', false);
    

    启用暗模式。您需要在组件的 .ts 文件中执行此操作。如果您将 Ionic 与 Angular 结合使用。

    编辑 1:

    将您的 ionViewDidEnter 更改为:

    async ionViewDidEnter() {
        await this.platform.ready().then(() => {
              document.body.classList.toggle('dark', false);
        })
    }
    

    【讨论】:

    • 异步 ionViewDidEnter() { await this.platform.ready(); document.body.classList.toggle('dark', false); }
    • 我需要在某些页面上强制禁用暗模式并在 .ts 文件中完成。该页面仍处于暗模式。
    猜你喜欢
    • 1970-01-01
    • 2023-03-05
    • 1970-01-01
    • 1970-01-01
    • 2014-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-02
    相关资源
    最近更新 更多