Data binding of v-model instruction when vue uses vuex

data binding of v-model instructions when vue uses vuex

there are two ways to write it. I"d like to ask you some of the differences.

method one
computed: {
    name: {
        get() {
          return this.$store.state.name
        },
        set(v) {
          // vuexmutations
          this.$store.commit("name", v)
        }
    }
}

so are these two writing methods feasible?

May.10,2021

the two are different. There is no testing, but the data of store can only be changed through commit . Method 2 should be feasible, but method 1 is not.
official document
ide/mutations.html" rel=" nofollow noreferrer "> https://vuex.vuejs.org/zh/gui.


here is rarely used in actual projects (not to say which is possible), since your application scenario with vuex is multiple peer components, or data sharing in routing. There are usually multiple store. Most projects use modules, and then use map in components.

Menu