Created
September 1, 2019 22:19
-
-
Save joewashere/67e7e35aa05df6cd5aeabf8632f040d5 to your computer and use it in GitHub Desktop.
Revisions
-
joewashere created this gist
Sep 1, 2019 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ // Product Star Rating Display Vue.component("prod-rating", { props: ["rating"], data(){ return { stars: [] } }, mounted: function () { let ratingTracker = this.rating; // Loop 5 times for 5 stars! for(i=1; i<=5; i++){ // Is the rating higher than our iterator? if(this.rating >= i){ // Full star for you! this.stars.push("icon-star-full"); ratingTracker--; }else{ // No? How about we see if we have anything left... if(ratingTracker % 1 !== 0){ // Half a star for you! this.stars.push("icon-star-half"); ratingTracker = 0; }else{ // Nothings left. No stars for you! this.stars.push("icon-star-empty"); ratingTracker--; } } } }, template: ` <div class="rating"> <span v-for="star in stars" :class="star + ' icon glyph'"></span> </div> ` });