Should we use v-model to modify Vuex store?

前端 未结 5 2133
被撕碎了的回忆
被撕碎了的回忆 2021-02-05 10:50

Hello I am beginner in Vue and I do have a problem that\'s really bugging me. I am wondering should we use v-model directive to modify vuex store? Vuex says that we should modif

5条回答
  •  旧时难觅i
    2021-02-05 11:38

    https://vuex.vuejs.org/guide/forms.html

    When using Vuex in strict mode, it could be a bit tricky to use v-model on a piece of state that belongs to Vuex.

    The "Vuex way" to deal with it is binding the 's value and call an action on the input or change event.

    Be sure to check out the simple "Two-way Computed Property" example on that page:

    
    
    computed: {
      message: {
        get () {
          return this.$store.state.obj.message
        },
        set (value) {
          this.$store.commit('updateMessage', value)
        }
      }
    }
    

提交回复
热议问题