12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- import Vue from 'vue'
- import Vuex from 'vuex'
- Vue.use(Vuex)
- const store = new Vuex.Store({
- state: {
- //公共的变量,这里的变量不能随便修改,只能通过触发mutations的方法才能改变
- tokenInfo: '',
- user: {},
- appear: {},
- power: []
- },
- mutations: {
- //相当于同步的操作
- setTokenInfo(state, newSetToken) {
- state.tokenInfo = newSetToken // 修改state里的tokenInfo
- },
- setUser(state, newSetUser) {
- state.user = newSetUser
- },
- setAppear(state,newSetAppear){
- state.appear = newSetAppear
- },
- setPower(state,newsetPower){
- state.power = newsetPower
- }
- },
- actions: {
- //相当于异步的操作,不能直接改变state的值,只能通过触发mutations的方法才能改变
- addTokenInfo(context, newSetToken) {
- context.commit('setTokenInfo', newSetToken)
- },
- addUser(context, newUser) {
- context.commit('setUser', newUser)
- },
- addAppear(context,newSetAppeaar){
- context.commit('setAppear',newSetAppeaar)
- },
- addPower(context,newSetPower){
- context.commit('setPower',newSetPower)
- }
- }
- })
- export default store
|