P
P
postya2020-10-10 17:33:12
Vue.js
postya, 2020-10-10 17:33:12

Why does the unknown action type error appear?

Nuxt application
using axios and vuex
Trying to request a url but getting an error
5f81c560e3811681797689.jpeg

vuex file news.js

import { NuxtAxiosInstance as $axios } from '@nuxtjs/axios'


export const state = () => ({
  news: []
})

export const actions = {
  async GET_NEWS_FROM_API ({commit}) {
    const news = await this.$axios.$get('http://icanhazip.com')
    commit('SET_NEWS_TO_STATE', news)
  }
}

export const mutations = {
  SET_NEWS_TO_STATE: (state, news) => {
    state.news = news;
    console.log(news)
  }
}

}

The component in which I call mapActions news.vue
import { mapActions } from 'vuex';

methods: {
    ...mapActions(['GET_NEWS_FROM_API']),
  },
  mounted() {
    this.GET_NEWS_FROM_API()
  },

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Gimir, 2020-10-11
@postya

You do not specify the full path to the action, in nuxte if you use this approach they are private and you must specify the full path.
This is how it should work:

...mapActions({GET_NEWS_FROM_API: 'news/GET_NEWS_FROM_API'}),

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question