javascript - A vuex problem
三叔
三叔 2017-07-05 11:08:08
0
1
828

As follows, how to get children and then update them to father.children, so that the page can be displayed in a list

state: {
    father: [
        {
            name: 'wang',
            children: []
        }
    ]
}


action: {
    getChildren(fatherId).then(children => {
        // 获得children,如何更新到father.children中
    });
}
三叔
三叔

reply all(1)
我想大声告诉你
state: {
    father: [
        {
            name: 'wang',
            children: []
        }
    ]
}, 
mutations:{
updateChildren(state,children){
    state.father[0].children = children;
}
},
actions: {
    updateChildren({commit}){
        getChildren(fatherId).then(children => {
            // 获得children,如何更新到father.children中
            commit("updateChildren",children );
        });
    }
}

That’s about it, let’s take a look at the documentation

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template