Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.


    Add Arrays of Data to the Vuex Store and Display Them in Vue.js Templates


    You add array of todos to the store simply by adding them to the state defined in your store/index.js file. You can access the array of todos using mapState then loop through and display them with v-for. This lesson walks you through the process of setting up todos in Vuex and displaying them in your Vue.js template.



    Become a Member to view code

    You must be a Pro Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    orLog In




    To add todos to our store we can just go ahead and delete the increment decrement and replace counter with todos. I'll add a task of eat and then duplicate this and change it to sleep and code. Just like we displayed the counter by mapping state, I can go ahead and display the todos in the same way. Todos.

    I'll get rid of these map mutations because I don't need them. Could also delete the buttons so that I can put in my todos, hit Save, and you'll see an array of todos rendered on the page. To style this a bit. I'm going to go to and go to the components and down to the lists.

    This list looks great so I'll just go here, scroll down, copy the HTML -- it's just HTML and some Tachyon classes -- and then I'll go ahead and paste that into my Index view. I'll clean up the formatting a little bit and just remove the padding I had before.

    Now, when I hit Save I'll have that same exact component -- I'll make this a bit smaller -- and that same component from Now I can delete all the other list elements except for the one I need. I'll add a v4 attribute and say todo of todos, the todo being each todo in the array.

    Instead of this Mackerel tabby I can just go ahead and make that todo.task. When I hit Save now you'll see eat, sleep, and code and I'll remove this cats, replace it with todos, so now we have todos. To learn more about all these Tachyon classes you see here, just go to There's a great list of them on the table of styles.