[Vuejs]-Vuex unknown action type: displayArticles

0๐Ÿ‘

โœ…

you have to dispatch the action, so in your .vue file you have to write :

mounted() {
      this.$store.dispatch("loadArticles");
    },

and to get the list of articles in your component you should use getter in your Store:

const getters = {
  getArticles: state => {
    return state.articles;
  }

and the computed will be like this:

    computed:{
      getArticlesFromStore(){
        return this.$store.getters.getArticles;
      }
    }

and then you call the computed leement in your HTML:

    <h1 v-for="article in getArticlesFromStore" :key="article.id">{{article.id}}</h1>

0๐Ÿ‘

You are trying to dispatch mutation. You need to use commit with mutations or move your displayArticles to actions. I imagine you meant to dispatch loadArticles?

Leave a comment