[Vuejs]-NativeScript Vue – VueX not working: cannot read property getters of undefined

2👍

The issue was the import statement import Vue from "vue" in file store.ts

I changed it to import Vue from "nativescript-vue" and now things seem to work.

I’ve created an issue here https://github.com/NativeScript/NativeScript/issues/8570 as the wrong import is added by following suggested getting started steps in the official website here: https://nativescript-vue.org/en/docs/getting-started/quick-start/

👤Ayudh

1👍

You have to define your state correctly to make getters work.

so you must have state like this:

  state:{
    user: null,
    status: {
      loggedIn: true
    }
  },

and then in your component:

  computed: {
    ...mapGetters({loggedIn: "auth/loggedIn"})
  },

and now you have access to your state with this.loggedIn

UPDATE

You must add store to your vue instance too:

const app = new Vue({
  el:'#app',
  store, // here
})

Leave a comment