【发布时间】:2019-09-25 22:45:17
【问题描述】:
我对 Vue 非常陌生,并且在现有代码方面遇到了问题。我已经计算了我的 Vuex 对象的属性
computed: {
...mapGetters([
'selectedObject'
])
},
在我的 Store.js 中,我将一个新对象添加到我的数组中,但 Vue 没有刷新。请注意,js是插入一个子对象
addNew({ commit, state }, payload) {
state.currentObject.paintings.push({
'config': {
'formName': 'My New Picture',
'orientation': 'portrait',
'referenceNumber': '',
'formType': ''
},
'id': (+new Date()),
'containers': [
{
'id': 'page-0',
'type': 'paintContainer',
'name': 'Page',
'image': '',
'children': []
}
]
})
state.currentPainting = state.currentForm.paintings[state.currentForm.paintings.length-1]
return FORM_SCHEMAS.update(state.currentSchemaId, state.currentForm)
}
调用 addNew 时,json 会正确更新数据
selectedObject getter如下
selectedObject: state => {
var data = state.currentForm; var formControl = null
if (state.selectedControlType === 'container') {
if (state.creatorMode === 'painting') {
return state.currentPainting.containers.find(container => container.id === state.selectedControlId)
}
}
return null
}
}
请帮忙
【问题讨论】: