theme.vue 584 B

12345678910111213141516171819202122
  1. <template>
  2. <div class="w-10 h-10 grid place-items-center rounded-full mt-3 hover:cursor-pointer">
  3. <Icon name="moon" @click="changeTheme()" v-if="isDark" />
  4. <Icon name="sun" @click="changeTheme()" v-else />
  5. </div>
  6. </template>
  7. <script setup lang="ts">
  8. import { useDark, useToggle } from '@vueuse/core'
  9. import { useAppStore } from '/admin/stores/modules/app'
  10. import { unref } from 'vue'
  11. const appStore = useAppStore()
  12. const isDark = useDark()
  13. const toggleDark = useToggle(isDark)
  14. function changeTheme() {
  15. appStore.setDarkMode(!unref(isDark))
  16. toggleDark()
  17. }
  18. </script>