[Vuejs]-How can I solve v-model with vuex?

2👍

getters are readonly, you can only update store state via mutations Vuex can’t match up getters to mutations automatically because they are user defined.

You can however specifically define the behaviour of get and set:

computed: {
  ...mapGetters(['foos']),
  // Define what happens when we get and set `date`
  date: {
    get() {
      return this.$store.state.foos.date;
    },
    set(newValue) {
      return this.$store.commit('foos/setDate', newValue);
    },
  },
}

Leave a comment