Created
July 17, 2019 02:56
-
-
Save DesKevinMendez/102b8393a61aea083bcd6f59e7c98740 to your computer and use it in GitHub Desktop.
BlogModule
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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