Skip to content

Instantly share code, notes, and snippets.

@MarGul
Created April 4, 2017 17:31
Show Gist options
  • Save MarGul/7ad2f92d1d978ea33824fec25e9511e0 to your computer and use it in GitHub Desktop.
Save MarGul/7ad2f92d1d978ea33824fec25e9511e0 to your computer and use it in GitHub Desktop.
<template>
<div class="ratings-component">
<i class="fa fa-star" aria-hidden="true" v-for="n in fullStars"></i>
<i class="fa fa-star-half-o" aria-hidden="true" v-if="halfStar"></i>
<i class="fa fa-star-o" aria-hidden="true" v-for="n in emptyStars"></i>
</div>
</template>
<script>
export default {
props: {
rating: {
type: Number,
required: true
},
max: {
type: Number,
default: 5
},
size: String
},
computed: {
fullStars() {
return Math.floor(this.rating);
},
halfStar() {
return ( this.rating % 1 >= 0.5 ) ? true : false;
},
emptyStars() {
let empty = this.max - this.fullStars.
return (this.halfStar) ? empty - 1 : empty;
}
},
created() {
console.log(this.fullStars);
}
}
</script>
<style lang="scss" scoped>
</style>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment