Vuex - Computed property "name" was assigned to but it has no setter Vuex - Computed property "name" was assigned to but it has no setter vue.js vue.js

Vuex - Computed property "name" was assigned to but it has no setter


If you're going to v-model a computed, it needs a setter. Whatever you want it to do with the updated value (probably write it to the $store, considering that's what your getter pulls it from) you do in the setter.

If writing it back to the store happens via form submission, you don't want to v-model, you just want to set :value.

If you want to have an intermediate state, where it's saved somewhere but doesn't overwrite the source in the $store until form submission, you'll need to create such a data item.


It should be like this.

In your Component

computed: {        ...mapGetters({                nameFromStore: 'name'            }),        name: {           get(){             return this.nameFromStore           },           set(newName){             return newName           }         }    }

In your store

export const store = new Vuex.Store({         state:{             name : "Stackoverflow"         },         getters: {                 name: (state) => {                     return state.name;                 }         }}


For me it was changing.

this.name = response.data;

To what computed returns so;

this.$store.state.name = response.data;