Yield generated for 2906dbd6-d7ad-4b06-81bc-e3509de54c56
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

45 lines
1.0 KiB

import { ArticlesService, CommentsService } from "@/common/api.service";
import { FETCH_ARTICLE, FETCH_COMMENTS } from "./actions.type";
import { SET_ARTICLE, SET_COMMENTS } from "./mutations.type";
export const state = {
article: {},
comments: []
};
export const actions = {
[FETCH_ARTICLE](context, articleSlug) {
return ArticlesService.get(articleSlug)
.then(({ data }) => {
context.commit(SET_ARTICLE, data.article);
})
.catch(error => {
throw new Error(error);
});
},
[FETCH_COMMENTS](context, articleSlug) {
return CommentsService.get(articleSlug)
.then(({ data }) => {
context.commit(SET_COMMENTS, data.comments);
})
.catch(error => {
throw new Error(error);
});
}
};
/* eslint no-param-reassign: ["error", { "props": false }] */
export const mutations = {
[SET_ARTICLE](state, article) {
state.article = article;
},
[SET_COMMENTS](state, comments) {
state.comments = comments;
}
};
export default {
state,
actions,
mutations
};