feat: 添加 vue-sonner,优化反馈
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
// app/stores/global.ts - 全局通用状态(主题等),持久化由 @nuxtjs/color-mode 统一管理(localStorage/cookie)
|
||||
export const useGlobalStore = defineStore("theme", () => {
|
||||
// useColorMode 会自动读写持久化存储,class 也由其挂到 <html>
|
||||
const colorMode = useColorMode();
|
||||
|
||||
/** 当前是否深色模式 */
|
||||
const isDark = computed(() => colorMode.value === "dark");
|
||||
|
||||
/** 切换深色 / 浅色 */
|
||||
const toggle = () => {
|
||||
colorMode.value = isDark.value ? "light" : "dark";
|
||||
};
|
||||
|
||||
/** vue-sonner Toaster 的 theme prop 值,跟随当前模式 */
|
||||
const toasterTheme = computed<"light" | "dark">(() =>
|
||||
isDark.value ? "dark" : "light"
|
||||
);
|
||||
|
||||
return { isDark, toggle, toasterTheme };
|
||||
});
|
||||
Reference in New Issue
Block a user