You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
24 lines
602 B
Vue
24 lines
602 B
Vue
<template>
|
|
<div class="form-check form-switch">
|
|
<label class="custom-control-label" for="darkSwitch">
|
|
<slot :state="sliderState" />
|
|
</label>
|
|
<input v-model="sliderState" type="checkbox" class="form-check-input" />
|
|
</div>
|
|
</template>
|
|
|
|
<script setup>
|
|
import { ref, watch } from 'vue';
|
|
import { themeConfig } from '@/main';
|
|
|
|
const sliderState = ref(themeConfig.getTheme() === 'dark');
|
|
|
|
watch(sliderState, (state) => {
|
|
themeConfig.setTheme(state ? 'dark' : 'light');
|
|
});
|
|
|
|
themeConfig.themeChangeHandlers.push((newTheme) => {
|
|
sliderState.value = newTheme === 'dark';
|
|
});
|
|
</script>
|