I want to change the class of 5 stars of FontAwesome Icons from regular to solid according to a numeric variable levelthat changes from 0 to 5
<template>
<div id="five-stars">
<font-awesome-icon icon="fa-solid fa-star" size="6x"/>
<font-awesome-icon icon="fa-regular fa-star" size="6x"/>
<font-awesome-icon icon="fa-regular fa-star" size="6x"/>
<font-awesome-icon icon="fa-regular fa-star" size="6x"/>
<font-awesome-icon icon="fa-regular fa-star" size="6x"/>
</div>
</template>
<script>
export default {
name: "ThreeScene",
data() {
return {
level: 1
};
}
}
Can you please tell me how can I do that without repeating the <div> five times? thanks in advance.
>Solution :
fa-${i <= level ? 'solid' : 'regular'} help you :
<template>
<div id="five-stars">
<font-awesome-icon v-for="i in 5" :key="i" :icon="`fa-${i <= level ? 'solid' : 'regular'} fa-star`" size="6x"/>
</div>
</template>
<script>
export default {
name: "ThreeScene",
data() {
return {
level: 1
};
}
}
</script>