vue.js - Vuex 状态更改不会刷新 Vue on Web
问题描述
我对 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
}
}
请帮忙
解决方案
使用 ...mapState 将您的数据与您的状态绑定,当您更改状态时,它会自动更新。
推荐阅读
- python - 将数据集中的某些单元格与python中的标量相乘
- reactjs - React 中的 Google Map API:如何为每个标记分配 InfoWindow
- javascript - 在 ECMAScript 规范中,我们可以准确地找到新词法环境的创建时间?
- hyperledger-fabric - ./startFabric 错误 - 背书客户端无法连接到 peer0.org1.example.com:7051:未能创建新连接:超出上下文截止日期
- apache-spark - 为什么分配给 Spark 驱动程序/执行程序的内存量与我从 spark-submit 传递的内存量不同?
- facebook - 向 Facebook Instant Games URL 添加参数,以便稍后在游戏中访问它
- html - 将边距顶部添加到 DIV 而不影响另一个 DIV
- c# - 如何在列表视图的项目顶部显示工具提示
- perl - perl 循环遍历多个数组
- html - 如何在引导程序 4 的导航栏下拉菜单中增加 div 大小