vue.jsnuxt.jsvuex

vuex unknown action type in NuxtJS


In my store I have:

export const state = () => ({
  searchedBrands: null,
  searchedCars: null,
  displaySearchResults: false,
  hovering: false,
  arrowIndex: -1,
})

export const getters = {
  displaySearchResults(state) {
    return state.displaySearchResults
  },
}

export const mutations = {
  setSearchResults(state, data) {
    state.searchedBrands = data.results[0].hits
    state.searchedCars = data.results[1].hits
  },
  displaySearchResults(state) {
    state.displaySearchResults = true
  },
}

export const actions = {
  setSearchResults({ commit }, data) {
    commit('setSearchResults', data)
  },
  displaySearchResults({ commit }) {
    commit('displaySearchResults')
  },
}

and I am trying to call an action in one my page component methods with:

this.$store.dispatch('displaySearchResults')

but it doesn't work and I get the following message:

[vuex] unknown action type: displaySearchResults

Am I doing something wrong?


Solution

  • Using the right namespace solved the issue and the Vuex action could work then.