Created
April 4, 2017 17:31
-
-
Save MarGul/7ad2f92d1d978ea33824fec25e9511e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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