javascript - 一個vuex的問題
三叔
三叔 2017-07-05 11:08:08
0
1
804

如下,如何取得children然後更新到father.children中,頁面就可以清單展示了

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


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

全部回覆(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 );
        });
    }
}

大概這樣吧,去看看文件吧

熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!