Static GitHub Issues

[2726] Vuex: dispatch - unknown action type

prev: Set plugin only on specific layouts
next: nuxt generate error, generated dist folder is not generated index.html

Hi,

I created my store store/map.js

export const state = () => ({
  loading: false,
  selected: null,
  markers: [{
    position: {lat: 50.2, lng: 14.372},
    name: 'XvFbd4rdej0',
    label: 'MyDevice',
    created: '26.1.2018',
    owner: 'PurrplingCat'
  }, {
    position: {lat: 50.117, lng: 14.227},
    label: 'YourDevice',
    name: 'DdFGB012erz',
    created: '30.1.2018',
    owner: 'CallMeFoxie'
  }, {
    position: {lat: 49.235, lng: 16.743},
    label: 'Another',
    name: 'FGfhVb3301f',
    created: '31.1.2018',
    owner: 'Elise Bauman'
  }],
  fulltext: []
})

export const mutations = () => ({
  FILL_MARKERS (state, markers) {
    if (!Array.isArray(markers)) {
      throw TypeError('Markers must be an array!')
    }
    state.markers = markers
  },
  TOGGLE_LOADING (state) {
    state.loading = !state.loading
  },
  SET_LOADING (state, loading) {
    state.loading = !!loading
  },
  SELECT (state, device) {
    state.selected = device
  },
  FILL_FULLTEXT (state, found) {
    if (!Array.isArray(found)) {
      throw TypeError('Found devices must be an array!')
    }
    state.fulltext = found
  },
  CLEAR_SELECT (state) {
    state.select = null
  },
  CLEAR_MARKERS (state) {
    state.markers = []
  },
  CLEAR_FULLTEXT (state) {
    state.fulltext = []
  }
})

export const actions = () => ({
  async fetchDevice ({ commit }, deviceName) {
    commit('TOGGLE_LOADING')
    let device = this.markers.find(el => el.name === deviceName)
    commit('TOGGLE_LOADING')
    if (!device) {
      let err = new Error(`'${deviceName}' not found!`)
      err.status = 404
      throw err
    }
    commit('SELECT', device)
    return device
  },
  async fulltext ({ commit }, query) {
    try {
      commit('TOGGLE_LOADING')
      let devices = await this.$axios.$get(`/search/${encodeURIComponent(query)}?scope=devices`)
      commit('TOGGLE_LOADING')
      commit('FILL_FULLTEXT', devices)
      return devices
    } catch (err) {
      commit('SET_LOADING', false)
      throw err
    }
  }
})

and I dispatch map/fetchDevice in my page pages/index.vue in following method:

loadDevice (marker) {
      this.query = marker.name
      this.$store.dispatch('map/fetchDevice', marker.name).catch(err => {
        this.error = err
      })
    }

but I got unknown action type: map/fetchDevice

I don't have any idey about problem. :'(

<!--cmty--><!--cmty_prevent_hook--><div align="right"><sub><em>This question is available on <a href="https://nuxtjs.cmty.io">Nuxt.js</a> community (<a href="https://nuxtjs.cmty.io/nuxt/nuxt.js/issues/c2367">#c2367</a>)</em></sub></div>