Error in Nuxt store setup-vuex] unknown action type: fetchProfiles

Viewed 132

I am new to NUXT, need help. I am trying to setup store and using it in one component but getting these errors in console.

getting messages
   'state' should be a method that returns an object in store/profiles.js.
      [vuex] unknown action type: fetchProfiles
      [vuex] unknown getter: allProfiles
import { mapGetters, mapActions } from "vuex";
export default {
 name: "Profiles",
 methods: {
   ...mapActions(["fetchProfiles"])
 },
 computed: mapGetters(["allProfiles"]),
 created() {
   this.fetchProfiles();
 }
};

Can anybody help me?

2 Answers

Try this:

const state = ()=> ({ 
    profiles: [], 
})

The state must be a method, you are directly returning an object.

You use the store in module mode.

You need to tell in witch module it is:

methods: {
   ...mapActions(["profiles/fetchProfiles"])
},
   computed: mapGetters(["profiles/allProfiles"]),
};

You should add profiles/ infront of it. Without profile/ it searches for an store/index.js file

Related