Search code examples
javascriptvue.jsvuexstore

Vuex method mapGetters can't fetch values


I have one modal for create user. There I need to call API and I am calling it through vuex store method i.e mapGetters. However it's not working. Can anyone tell me whats missing here?

create-user file.

import {mapGetters} from "vuex"

computed: {
    ...mapGetters("Entities", ["getEntities"]),
}

entities file:

const state = () => ({
  entities: []
})
const getters = {
  getEntities: (state) => state.entities
}
const mutations = {
  setEntities(state, entities) {
    state.entities = [...entities]
  }
}

const actions = {
  async fetchEntities({commit}) {
    return await axios.get('/entity')
      .then((resp) => {
          commit("setEntities", resp)             
          return true
      })
  }
}

Solution

  • I found the solution. Actually, I wasn't calling fetchEntities mapAction in my vue file on created() method. fetchEntities fetch the data and then put it to the mapGetters.

    Thanks for your support and for giving valuable time to the issue.