useTheme

Tailwind Mobile comes with handy useTheme hook to detect currently active theme (ios or material) set by App component or TailwindMobileProvider.

<!-- App.vue -->
<template>
  <!-- set theme on App component -->
  <twm-app theme="ios">
    <HomePage />
  </twm-app>
</template>
<script>
  import { twmApp } from 'tailwind-mobile/vue';
  import HomePage from './path/to/HomePage.vue';

  export default {
    components: {
      twmApp,
      HomePage,
    },
  };
</script>
<!-- HomePage.vue -->
<template>
  <twm-page>
    <p>Theme is {{theme === 'ios' ? 'iOS' : 'Material'}}</p>
  </twm-page>
</template>
<script>
  import { useTheme, twmPage } from 'tailwind-mobile/vue';

  export default {
    components: {
      twmPage,
    },
    setup() {
      // get currently set theme
      const theme = useTheme();

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

      return {
        theme,
      };
    },
  };
</script>
Code licensed under MIT.
2021 © Tailwind Mobile by nolimits4web.