Fix – Vuex computed property was assigned to but it has no setter

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…

The post Fix – Vuex computed property was assigned to but it has no setter appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Deven

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:

<template>
  <div id="app">
    <router-view></router-view>
    <loading v-model="isLoading"></loading>
  </div>
</template>

<script>
  import { Loading } from 'vux'
  import { mapState } from 'vuex'

  export default {
    name: 'app',
    components: {
      Loading
    },
    computed: {
      ...mapState({
        isLoading: state => state.isLoading
      })
      }
    }
  }
</script>

Your store file should be like below:

import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const state = {
  isLoading: false
}

const mutations = {
  updateLoadingStatus (state, payload) {
    state.isLoading = payload.isLoading
  }
}

export default new Vuex.Store({
  state,
  mutations
})

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:

<template>
  <div id="app">
    <router-view></router-view>
    <loading :value.sync="isLoading"></loading>
  </div>
</template>

<script>
  import { Loading } from 'vux'
  import { mapState } from 'vuex'

  export default {
    name: 'app',
    components: {
      Loading
    },
    computed: {
      ...mapState({
        isLoading: state => state.isLoading
      })
    }
  }
</script>

The post Fix – Vuex computed property was assigned to but it has no setter appeared first on CodeSource.io.


This content originally appeared on CodeSource.io and was authored by Deven


Print Share Comment Cite Upload Translate Updates
APA

Deven | Sciencx (2021-02-23T17:41:59+00:00) Fix – Vuex computed property was assigned to but it has no setter. Retrieved from https://www.scien.cx/2021/02/23/fix-vuex-computed-property-was-assigned-to-but-it-has-no-setter/

MLA
" » Fix – Vuex computed property was assigned to but it has no setter." Deven | Sciencx - Tuesday February 23, 2021, https://www.scien.cx/2021/02/23/fix-vuex-computed-property-was-assigned-to-but-it-has-no-setter/
HARVARD
Deven | Sciencx Tuesday February 23, 2021 » Fix – Vuex computed property was assigned to but it has no setter., viewed ,<https://www.scien.cx/2021/02/23/fix-vuex-computed-property-was-assigned-to-but-it-has-no-setter/>
VANCOUVER
Deven | Sciencx - » Fix – Vuex computed property was assigned to but it has no setter. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/02/23/fix-vuex-computed-property-was-assigned-to-but-it-has-no-setter/
CHICAGO
" » Fix – Vuex computed property was assigned to but it has no setter." Deven | Sciencx - Accessed . https://www.scien.cx/2021/02/23/fix-vuex-computed-property-was-assigned-to-but-it-has-no-setter/
IEEE
" » Fix – Vuex computed property was assigned to but it has no setter." Deven | Sciencx [Online]. Available: https://www.scien.cx/2021/02/23/fix-vuex-computed-property-was-assigned-to-but-it-has-no-setter/. [Accessed: ]
rf:citation
» Fix – Vuex computed property was assigned to but it has no setter | Deven | Sciencx | https://www.scien.cx/2021/02/23/fix-vuex-computed-property-was-assigned-to-but-it-has-no-setter/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.