search

Home  >  Q&A  >  body text

javascript - A vuex problem

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

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

<code>state: {

    father: [

        {

            name: 'wang',

            children: []

        }

    ]

}

 

 

action: {

    getChildren(fatherId).then(children => {

        // 获得children,如何更新到father.children中

    });

}</code>

三叔三叔2815 days ago912

reply all(1)I'll reply

  • 我想大声告诉你

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

    1

    2

    3

    4

    5

    6

    7

    8

    9

    10

    11

    12

    13

    14

    15

    16

    17

    18

    19

    20

    21

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

            });

        }

    }</code>

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

    reply
    0
  • Cancelreply