1

I'm trying to use Vuex store in my Nuxt project. After following a guide on how to get started, I'm getting a this.$store is undefined error.

store/index.js file:

export const state = () => ({
    userdata: {}
})

export const mutations = {
    setUserdata(state, value){
        state.userdata = value
    }
}

export const getters = {
    GetUserdata(state){ return state.userdata}
}`

pages/login.vue script:

import Vue from 'vue'
export default Vue.extend({
    name: 'LoginSuccessPage',
    async created() {
        var token = this.$route.query.token
        var data = await fetch("http://localhost:3500/profile/"+token)
        var jsondata = await data.json()
        this.$store.dispatch("userdata",jsondata)
     }
})`
csanszan1
  • 31
  • 4
  • I have a working example of a Nuxt + Vuex setup here: https://stackoverflow.com/a/74819111/8816585 Also, why do you use `extend` here? I'm not familiar with it and hence, not sure of what it does exactly. – kissu Dec 18 '22 at 23:15

1 Answers1

2

Removing vuex from package.json fixed the issue.

kissu
  • 40,416
  • 14
  • 65
  • 133