Answer the question
In order to leave comments, you need to log in
Why doesn't action work in store nuxt?
Good afternoon.
I have this design in store/index.js
import axios from 'axios';
export const state = () => ({
catalog: []
})
export const mutations = {
SET_CATALOG_TO_STATE: (state,catalog) => {
state.catalog = catalog;
}
}
export const actions = {
GET_BASKET_FROM_API({commit}) {
return this.$axios.$get('./json/catalog.json', {
method: "GET"
})
.then((catalog) => {
console.log('xyu')
console.log(catalog)
commit('SET_CATALOG_TO_STATE', catalog.data);
return catalog;
})
.catch((error) => {
console.log(error)
return error;
})
}
}
export const getters = {
CATALOG(state) {
return state.catalog
}
}
import { mapGetters,mapActions} from 'vuex';
export default {
data() {
return {
catalog: [],
}
},
computed: {
...mapGetters([
'CATALOG'
]),
startStore: function() {
return this.$store.state.catalog
}
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question