🔥 遇见我们的新项目 t0ggles - 您终极的项目管理工具! 🔥

useTheme

Konsta UI 提供了方便的 useTheme 钩子来检测当前活动的主题(iosmaterial),该主题由 App 组件KonstaProvider 设置。

<!-- App.svelte -->
<script>
  import { App } from 'konsta/svelte';
  import HomePage from './path/to/HomePage.svelte';
</script>

<!-- set theme on App component -->
<App theme="ios">
  <HomePage />
</App>
<!-- HomePage.svelte -->
<script>
  import { useTheme, Page } from 'konsta/svelte';

  let theme;
  theme = useTheme((newValue) => {
    // to keep it reactive, update value on theme update in parent components
    theme = newValue;
  });

  console.log(theme); // -> 'ios'
</script>

<Page>
  <p>Theme is {theme === 'ios' ? 'iOS' : 'Material'}</p>
</Page>
代码许可证: MIT.
2022 © Konsta UI 作者: nolimits4web.