0
我目前做如下:2种方式与对象内嵌套的属性绑定。 (VueJS + VueX)
<script>
export default {
computed: {
editingItem: {
get() {
return this.$store.getters['editing/editingItem'];
},
set(newValue) {
this.$store.commit('editing/UPDATE_EDITING', newValue);
}
},
editingItemName: {
get() {
return this.editingItem.name;
},
set(newValue) {
this.editingItem.name = newValue;
this.editingItem = this.editingItem;
}
}
},
}
</script>
我是不是在复杂呢? editingItemName set()的第二行是解决方法,使editItem set()函数触发。
你能解释一下你正在试图acheive什么?你是否试图实现与商店的双向数据绑定? – LiranC
@LiranC是的。我可以用一个简单的状态值来做到这一点,但是如果它有嵌套的参数,我不得不像我做过的那样做,或者为Store上的每个参数提交一个提交。我喜欢这个例子的原因是,这样我只需要有一个突变。 –