Vue
HTML
<div id="app">
<ul>
<li v-for="category in categories">
<div> {{ category.title }} </div>
<ul>
<li v-for="(subcat, index) in category.sub">
<div v-on:click="changeCategory(index)" :class="{ active: isActive(index) }">{{ subcat.title }}</div>
</li>
</ul>
</li>
</ul>
</div>
CSS
ul ul {
padding-left: 40px
}
.active {
color: #f00
}
Vue
var app = new Vue({
el: '#app',
data: {
active: '',
categories: [
{
title: 'Первое меню',
sub: [
{
title: "Первый пункт",
image: "first_1.png",
a: 2,
b: 3
}, {
title: "Второй пункт",
image: "first_2.png",
a: 3,
b: 5
}, {
title: "Третий пункт",
image: "first_3.png",
a: 3,
b: 6
}
]
}, {
title: 'Второе меню',
sub: [
{
title: "Первый пункт",
image: "second_1.png",
a: 5,
b: 4
}, {
title: "Второй пункт",
image: "second_2.png",
a: 6,
b: 6
}, {
title: "Третий пункт",
image: "second_3.png",
a: 8,
b: 7
}
]
}
]
},
methods: {
changeCategory(index) {
this.active = index;
},
isActive: function (index) {
return this.active === index
}
}
})