[Vuejs]-Best way to change FontAwsome stars class regular to solid

1๐Ÿ‘

โœ…

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>

0๐Ÿ‘

Use a v-for loop

<template>
    <div id="five-stars">
      <font-awesome-icon 
        v-for="level in 5" 
        :key="level"
        :icon="`${level} fa-star" 
        size="6x"
      />
    </div>
</template>

<script setup>
import { ref } from 'vue'

const data = ref([
  'fa-solid',
  'fa-regular',
  'fa-solid',
  'fa-regular',
  'fa-solid'
])

</script>

note that the variable level will start with the value of 1, not 0.

๐Ÿ‘คRemicaster

Leave a comment