我正在try 使用Vue.set()
更新Vue 2中的状态对象.
这就是对象的外观:
state: {
entries: [
// entry 1
fields: {
someProperties : ''
// here I would like to add another property named 'googleInfos'
}
], [
// entry 2
fields: {
someProperties : ''
// here I would like to add another property named 'googleInfos'
}
]
}
到目前为止,我正在用这个Mutations 来更新它.我分别对每个条目进行变异,因为它们有不同的内容.
ADD_GOOGLE_INFOS (state, {index, infos}) {
state.entries[index].fields.googleInfos = infos
}
现在,我试图实现Vue.set()
以避免change detection caveat.
我的问题是我找不到合适的方法来添加它.
下面是Vue的工作方式.set()应该可以工作:
Vue.set(state.object, key, value)
所以我try 了这个,它似乎不起作用,因为state.entries[index]
不是一等物品:
Vue.set(state.entries[index], 'fields.googleInfos', infos)
但这也不起作用:
Vue.set(state.entries, '[index].fields.googleInfos', infos)
有人知道我做错了什么吗?