1. uni.scss
$white: #FFFFFF;
$dark: #000000;
.light {
background: $dark;
color: $white;
}
.dark {
background: $white;
color: $dark;
}
2. store
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
state: {
vuex_theme: uni.getStorageSync('vuex_theme') ? uni.getStorageSync('vuex_theme') : 'light'
},
mutations: {
changeTheme(state, theme) {
state.vuex_theme = theme;
uni.setStorageSync('vuex_theme', theme);
}
}
})
export default store
3. main.js
import store from '@/store/index'
const app = new Vue({
...App,
store
})
4. index
> 直接在页面中使用