Update data using vuex

前端 未结 4 2042
Happy的楠姐
Happy的楠姐 2021-01-02 14:39

As Vuex, I\'m trying to update an object using form. My code like this.

In store:

const state = {
   categories: []
};

//mutations:
[mutationType.UP         


        
4条回答
  •  醉话见心
    2021-01-02 15:11

    You just need one line code because the javascript object has reference capabilities

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

提交回复
热议问题