<ul> <li v-for="(item, parentIndex) in tagsList"> <div class="tagsParent">{{ item.name }}</div> <ul class="tagsChild"> <li @click="addStyle(tagsItem.id,parentIndex)" class="tagsChild-defalut" :class="{ 'tagsChild-active':tagsItem.id === tagsList[parentIndex].selected }" v-for="(tagsItem, childIndex) in item.tags" :key="childIndex"> {{ tagsItem.name}} </li> </ul> </li> </ul>
``
addStyle(childId,parentIndex) {
this.tagsList[parentIndex].selected = childId
const newArr = []
this.tagsList.map(item => {
if (item.selected !== -1) {
newArr.push([item.selected])
}
})
this.tags = []
this.tags = newArr
this.getList()
},