Search code examples
javascriptvuexnuxt.js

NuxtJs Computed property "isLoggedIn" was assigned to but it has no setter


For some reason i keep getting this error no matter what I try.

enter image description here

This is how I'm getting and updating the computed property

  computed: {
    isLoggedIn() {
    return this.$store.state.user.isLoggedIn;
   }
  },
  methods: {
   handleAuthenticate(value) {
     this.$store.commit("user/authenticate", value);
   }
  }

I've already looked up similar answers here and this doesn't fix the issue

computed: {
  isLoggedIn: {
    get() {
      return this.$store.state.user.isLoggedIn;
    },
    set(newValue) {
    this.$store.commit("user/authenticate", newValue);
   }
  }
},

I'm wondering if this is because I'm using Nuxt instead of just plain Vuejs. I followed the example on Nuxt official doc but still getting the error everytime i call my handleAuthenticate method:

https://nuxtjs.org/examples/vuex-store/ https://codesandbox.io/s/github/nuxt/nuxt.js/tree/dev/examples/vuex-store?from-embed

this is the structure of my current user state and mutations

state.js

export default () => ({
  isLoggedIn: false
})

mutations.js

export default {
 authenticate(state, value) {
 state.isLoggedIn = value;
 }
}

getters.js

   export default {
    isLoggedIn(state) {
     return state.isLoggedIn
    }
   }

i'm not exactly sure what the problem is as i followed the example. Maybe i missed something. Any help would be appreciated. thanks!


Solution

  • for those who encountered a similar issue. It turns I was received the error because i was using the isLoggedIn with v-model property.

     <v-navigation-drawer
      v-model="isLoggedIn"
      :mini-variant="miniVariant"
      :clipped="clipped"
      fixed
      app
    >
    
    </v-navigation-drawer>
    

    I fixed it by returning the value on set method

    isLoggedIn: {
      get() {
        return this.$store.state.user.isLoggedIn;
      },
      set(val) {
        return val;
      }
    }