S
S
SPART4K632021-07-02 11:46:24
Vue.js
SPART4K63, 2021-07-02 11:46:24

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
  }
}


And I want to get a getter in the component:
import { mapGetters,mapActions} from 'vuex';
    export default {
      data() {
        return {
          catalog: [],
        }
      },
      computed: {
          ...mapGetters([
            'CATALOG'
          ]),
          startStore: function() {
            return this.$store.state.catalog
          }
      }
    }


Please tell me why my action does not work? Nothing even consolidates

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question