A
A
Alexander Koregin2019-05-15 15:17:18
Vue.js
Alexander Koregin, 2019-05-15 15:17:18

How to correctly display a list in html through Vue.JS?

I have a UL list

<ul class="aside-list" id="firstLevelCategories">
            <li class="aside-list__item"><img src="images/face.png" alt="Face icon"><a class="aside-list__link" v-for="item in items" href="#">{{ item.message }}</a></li>
            <li class="aside-list__item"><img src="images/hair.png" alt="Hair icon"><a class="aside-list__link" v-for="item in items" href="#">{{ item.message }}</a></li>
            <li class="aside-list__item"><img src="images/body.png" alt="Body icon"><a class="aside-list__link" v-for="item in items" href="#">{{ item.message }}</a></li>
            <li class="aside-list__item"><img src="images/mineral.png" alt="Mineral icon"><a class="aside-list__link" v-for="item in items" href="#">{{ item.message }}</a></li>
            <li class="aside-list__item"><img src="images/child.png" alt="Child icon"><a class="aside-list__link" v-for="item in items" href="#">{{ item.message }}</a></li>
        </ul>

And with this code, I display all the elements from the array
let firstLevelCategories = { 
    0: "Уход за лицом",
    1: "Уход за волосами",
    2: "Уход за телом",
    3: "Минеральная косметика",
    4: "Уход за детьми"
}

for (let i = 0; i < Object.keys(firstLevelCategories).length; i++) {
    let firstLevelMenu = new Vue({
        el: '#firstLevelCategories',
        data: {
          items: [
            { message: firstLevelCategories[i] }
          ]
        }
    })
}

But it displays only the first element, help me figure out the problem

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Darkhan Kamaliev, 2019-05-15
@dragonika8

v-for to help you

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question