seepur/resources/scripts/applications/home/state.vuex.ts
2020-03-17 18:16:34 -04:00

27 lines
528 B
TypeScript

import Vue from 'vue';
import Vuex, { Store } from "vuex";
import Services from '../services';
Vue.use(Vuex);
const store = new Store({
strict: true,
state: {
user: null,
},
getters: {
user(state) {
return state.user;
}
},
mutations: {
setUser: (state, user) => {
state.user = user;
}
},
actions: {
getUser: async (ctx, userId?: number) => {
const user = await Services.ApiService.getUser(userId);
ctx.commit('setUser', user);
},
}
});
export default store;