Answer the question
In order to leave comments, you need to log in
Vue/Vuex - How to correctly change the state of a component in mutations?
I need to parse the API using vue and vuex
There is a request from the component:
this.$store.dispatch('FETCH_STORIES');
Action:
FETCH_STORIES: ({ commit }) => {
axios.get("http://hn.algolia.com/api/v1/search?tags=front_page")
.then(response => {
let result = response.data;
commit("APPEND_STORY", result);
})
},
APPEND_STORY: (state, article) => {
state.stories.push(article);
},
state: {
stories: [],
}
APPEND_STORY: (state, payload) => {
state.stories = payload;
},
Answer the question
In order to leave comments, you need to log in
To get rid of the cycle, you can make an object or a map with the id key instead of an array. Why is there crap in the store - you need to look at the code. The mutation is generally correct.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question