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上的每個參數提交一個提交。我喜歡這個例子的原因是,這樣我只需要有一個突變。 –