Ecmascript 6 Vuex:提交对象,然后按ID查找它

Ecmascript 6 Vuex:提交对象,然后按ID查找它,ecmascript-6,vuejs2,vuex,Ecmascript 6,Vuejs2,Vuex,我正在尝试使用此方法将某些内容提交到Vuex状态 getVariableLookup: ({ commit, _state }, payload) => { http.get(`/frame_variables/${payload}`) .then(response => { commit('addVariableLookup', response.data.frame_variable.body) }) } 这很好,但我想将有效负载与响应一起存储。

我正在尝试使用此方法将某些内容提交到Vuex状态

getVariableLookup: ({ commit, _state }, payload) => {
  http.get(`/frame_variables/${payload}`)
    .then(response => {
      commit('addVariableLookup', response.data.frame_variable.body)
    })
}
这很好,但我想将
有效负载
与响应一起存储。我似乎不能像这样把它当作一件物品来交付

commit('addVariableLookup', { id: payload, body: response.data.frame_variable.body })
该方法返回以下内容:

更新

结果是数据设置得很好,我无法用以下代码检索数据:

const body = this.variableLookups.find(x => x.id === v.v_id)

this.variableLookups
将返回所有这些内容。如何找到单个对象?

抓取主体以获取相关id应该是:

const entry=this.variableLookups.find(x=>x.id==v.v\u id)
const body=条目?entry.body:null
是否需要三值/
null
,取决于您是否已经有了防止这种情况发生的逻辑。在尝试获取数据之前,您需要小心等待,直到操作加载了数据


使用对象将ID映射到实体可能比使用数组更好。向对象添加属性的常见警告适用。

如何定义
addVariableLookup
变体?另外,如果您使用的是vue devtools,您能看到突变火吗?这里不一定有任何错误。Getter和Setter只是意味着这些属性定义了JS Getter和Setter,这是Vue添加它们作为反应系统的一部分时所期望的。如果您展开这些对象,您应该会找到隐藏在其中的正确值。My bad将更新问题。vue devtools告诉我我得到了正确的数据。。。等待操作加载数据后。。。我什么时候学习?多谢各位。