小编Luk*_*den的帖子

使用Vuex更新数组中的对象

如何使用Vuex更新数组内的对象?我试过这个,但它不起作用:

const state = {
  categories: []
};

// mutations:
[mutationType.UPDATE_CATEGORY] (state, id, category) {
  const record = state.categories.find(element => element.id === id);
  state.categories[record] = category;
}

// actions:
updateCategory({commit}, id, category) {
  categoriesApi.updateCategory(id, category).then((response) => {
    commit(mutationType.UPDATE_CATEGORY, id, response);
    router.push({name: 'categories'});
  })
}
Run Code Online (Sandbox Code Playgroud)

javascript vue.js vuex vuejs2

6
推荐指数
1
解决办法
1万
查看次数

标签 统计

javascript ×1

vue.js ×1

vuejs2 ×1

vuex ×1