李凌
2025-12-16 9337c3cf960b60078558b7f942fd27f1ab39364b
src/main.js
@@ -1,6 +1,7 @@
import { createApp } from 'vue'
import './assets/css/index.scss'
import './assets/css/init.scss'
import './assets/theme/index.scss'
import 'vant/lib/index.css'
import fxHeader from '@/components/fx-header'
import 'default-passive-events'
@@ -13,8 +14,12 @@
import pinia from '@/store'
import store from '@/store/store'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import { getStorage } from '@/utils/utis'
pinia.use(piniaPluginPersistedstate)
// 初始化主题为黑夜模式
const theme = getStorage('theme') || 'dark'
window.document.documentElement.setAttribute('data-theme', theme)
const app = createApp(App)
const title = import.meta.env.VITE_APP__TITLE
@@ -26,4 +31,11 @@
app.use(pinia)
app.use(store)
// 确保store中的主题状态与DOM同步
app.mount('#app')
// 在应用挂载后初始化主题
if (store.state.vant && store.state.vant.theme !== theme) {
  store.commit('vant/SET_THEME', theme)
} else if (!store.state.vant || !store.state.vant.theme) {
  store.commit('vant/SET_THEME', theme)
}