基本介绍
创建store
import Vuex from 'vuex'
const store = new Vuex.Store({
state: {
name: '',
obj: '',
age: 18
},
getters: {
fakeAge: (state, getters) => {
return state.age + 2;
}
},
mutations: {
grow(state) { state.age++; },
changeLoading(state, payload) { state.loading = payload.loading; }
},
actions: {
getNickName(context) {
context.commit('changeLoading', { loading: true });
// or
// context.commit({ type: 'changeLoading', payload: { loading: true } });
}
},
});