import Vue from 'vue' import Vuex from 'vuex' Vue.use(Vuex) const store = new Vuex.Store({ state: { theme: 'light' // 默认浅色主题 }, mutations: { setTheme(state, theme) { state.theme = theme // 保存到本地存储 uni.setStorageSync('theme', theme) } }, actions: { initTheme({ commit }) { // 从本地存储读取主题设置 const savedTheme = uni.getStorageSync('theme') if (savedTheme) { commit('setTheme', savedTheme) } }, toggleTheme({ commit, state }) { const newTheme = state.theme === 'light' ? 'dark' : 'light' commit('setTheme', newTheme) } } }) export default store