Vuex Mapstate Setter

Posted on  by admin
If you are Getting Vuex computed property was assigned to but it has no setter error.

This article will help you fix the issue. The error happens because of the v-model. It’s trying to change the value of isLoading but mapState will only create getters. Consider the example below:. For your component file:. Your store file should be like below:.

You can make things work by binding the value to the isLoading and then handle the update by committing the mutations on the @input.

Consider the example below:.

In this tutorial, we’ll look at how we can access the State from our Vuex store from within our components, both directly and with the help of Getters. If we take a look at our main.js file, we see we’re importing our Vuex store file, and providing it to our root Vue instance.

This was set up for us because we selected Vuex when we created our project with the Vue CLI.

stakx - no longer contributing
80.1k