您的位置:首页 > 科技 > 能源 > Vue3-cloud-music前段探索

Vue3-cloud-music前段探索

2024/12/23 7:08:18 来源:https://blog.csdn.net/windxf/article/details/139488119  浏览:    关键词:Vue3-cloud-music前段探索

首页App.vue

<script setup lang="ts">
import LayOut from '@/components/Layout/Layout.vue';
import { zhCN, useDialog } from 'naive-ui';
import { onMounted } from 'vue';
import { useMainStore } from './stores/main';
const mainStore = useMainStore();onMounted(() => {mainStore.initDocumentTheme();let media = window.matchMedia('(prefers-color-scheme: dark)');media.addEventListener('change', (e) => {mainStore.changeTheme(e.matches?'dark':'light');//light});
});
</script>
<template><n-config-provider :locale="zhCN" :theme="mainStore.activeTheme"><n-loading-bar-provider><div class="w-100vw"><n-message-provider><n-dialog-provider><LayOut /></n-dialog-provider></n-message-provider></div></n-loading-bar-provider></n-config-provider>
</template><style>
@import "@/assets/base.css";
::-webkit-scrollbar {width: 5px;height: 5px;background-color: transparent;
}
::-webkit-scrollbar-thumb{width: 5px;@apply bg-gray-400/40;border-radius: 10px;
}
</style>

主题颜色切换使用了n-switch

        <n-switch :value="mainStore.isActiveDarkTheme" size="large" :on-update:value="handleThemeSwitchUpdateChange"><template #checked-icon><n-icon :component="Moon" /></template><template #unchecked-icon><n-icon :component="SunnySharp" /></template></n-switch>

回调函数是handleThemeSwitchUpdateChange

const handleThemeSwitchUpdateChange = () => {mainStore.toggleTheme();

ts中的自定义类对象mainStore

    toggleTheme() {const theme = this.theme ==='dark'? 'light':'dark';this.changeTheme(theme);},changeTheme(theme:'dark' | 'light') {if (theme === 'dark') {//这个设置html外围的颜色document.documentElement.classList.add('dark');document.documentElement.style.colorScheme = 'dark';} else {//这个设置html外围的颜色document.documentElement.classList.remove('dark');document.documentElement.style.colorScheme = '';}// 设置网页的配色方案为dark this.theme = theme;//这个设置navie-ui的空间localStorage.theme = theme;},

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com