Maison  >  Questions et réponses  >  le corps du texte

javascript - Un problème avec Vuex

Comme suit, comment obtenir des enfants puis les mettre à jour vers père.enfants, afin que la page puisse être affichée dans une liste

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


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

répondre à tous(1)je répondrai

  • 我想大声告诉你

    我想大声告诉你2017-07-05 11:10:08

    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 );
            });
        }
    }

    C’est probablement ça. Jetons un coup d’œil à la documentation

    répondre
    0
  • Annulerrépondre