mirror of
https://github.com/aelve/guide.git
synced 2024-12-26 14:23:14 +03:00
35 lines
861 B
TypeScript
35 lines
861 B
TypeScript
|
import { ActionTree, GetterTree, MutationTree, ActionContext, Module } from 'vuex'
|
||
|
import { ICategory, CategoryService } from 'client/service/Category'
|
||
|
|
||
|
interface CategoryState {
|
||
|
categoryList: ICategory[]
|
||
|
}
|
||
|
|
||
|
const state: CategoryState = {
|
||
|
categoryList: []
|
||
|
}
|
||
|
|
||
|
const getters: GetterTree<CategoryState, any> = {}
|
||
|
|
||
|
const actions: ActionTree<CategoryState, any> = {
|
||
|
async loadCategoryList({ commit }: ActionContext<CategoryState, any>): Promise<any> {
|
||
|
const data: ICategory[] = await CategoryService.getCategoryList()
|
||
|
commit('setCategoryList', data)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const mutations: MutationTree<CategoryState> = {
|
||
|
setCategoryList: (state: CategoryState, payload: ICategory[]) => {
|
||
|
state.categoryList = payload
|
||
|
}
|
||
|
}
|
||
|
|
||
|
const category: Module<CategoryState, any> = {
|
||
|
namespaced: true,
|
||
|
state,
|
||
|
getters,
|
||
|
actions,
|
||
|
mutations
|
||
|
};
|
||
|
|
||
|
export default category
|