1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
| 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
|
|