Skip to content

Instantly share code, notes, and snippets.

@DesKevinMendez
Created July 17, 2019 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save DesKevinMendez/102b8393a61aea083bcd6f59e7c98740 to your computer and use it in GitHub Desktop.
Save DesKevinMendez/102b8393a61aea083bcd6f59e7c98740 to your computer and use it in GitHub Desktop.
BlogModule
import { GetterTree, ActionTree, MutationTree } from 'vuex';
import { State } from '@/store/interfaces/Blog.ts';
// Establece los types de los modulos store
import blogTypes from '@/store/types/BlogTypes';
const namespaced: boolean = true;
const state: State = {
blogs: []
};
const getters: GetterTree<State, any> = {
[blogTypes.getters.GETBLOGS] : ( state ) => {
return state.blogs;
},
};
const mutations: MutationTree<State> = {
[blogTypes.mutations.SETBLOGS]: (state, blogs) => {
state.blogs = blogs;
},
};
const actions: ActionTree<State, any> = {
[blogTypes.actions.ACTBLOGS]: ({ commit, state }, blog) => {
const blogGuardados = state.blogs;
commit(blogTypes.mutations.SETBLOGS, blogGuardados.concat(blog));
},
};
export default {
namespaced,
state,
getters,
mutations,
actions,
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment