我们应该使用v-model来修改Vuex store吗? [英] Should we use v-model to modify Vuex store?
问题描述
您好,我是 Vue 的初学者,我确实遇到了一个真正困扰我的问题.我想知道我们应该使用 v-model 指令来修改 vuex 存储吗?Vuex 说我们应该只通过突变修改 vuex 存储,但 v-model 使一切变得更容易和更短.(我问是因为我找不到明确的答案)
https://vuex.vuejs.org/guide/forms.html
<块引用>在严格模式下使用 Vuex 时,在属于 Vuex 的状态片段上使用 v-model
可能有点棘手.
Vuex 方式"处理它是绑定 的值并对输入或更改事件调用操作.
请务必查看简单的双向计算属性"该页面上的示例:
<块引用>计算:{信息: {得到 () {返回 this.$store.state.obj.message},设定值) {this.$store.commit('updateMessage', value)}}}
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 modify vuex store only by mutations but v-model makes everything easier and shorter.(I am asking because i couldn't find clear answer)
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
<input>
'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:
<input v-model="message"> computed: { message: { get () { return this.$store.state.obj.message }, set (value) { this.$store.commit('updateMessage', value) } } }
这篇关于我们应该使用v-model来修改Vuex store吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!