I have a problem with the NuxtJs store it always returns undefined I found a lot of similar questions but none has fixed the problem. here's my code:
import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex)
const store = new Vuex.Store({
state(){
return{
count: 500
}
},
getters: {
getCount: (state) => {
state.count
}
},
})
then I tried getting it this way
this.$store.getters.getCount
also tried this
computed: {
...mapGetters(['getCount'])
},
created(){
console.log("count: "+this['getCount'])
}

Nuxt sets up a store automatically for you, so you don't need to instantiate your own store.
Remove the setup code:
And create
store/index.jswith the following contents:Now, you can access the store in your components:
demo