Iterate through element and set class within
08 February 2022
JavaScript
Web
Development
Vue
template
<div :class="(badgeBars(car.level.option_value) >= index )?'active':''" v-for="(item, index) in items" :key="item"></div>
script
export default {
name: "wCar",
data() {
return {
items: [
'A1', 'A2','B1','B1+','B2','C1'
]
}
},
methods: {
badgeBars(level){
return this.items.indexOf(level);
},
},
props: {
car: [Object, String],
wicon: String,
index: Number
},
};