star.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <template>
  2. <section class="starComponent">
  3. <i class="star icon fill"
  4. v-for="(m,i) in calcNum.fill" :key="'fill' + i"></i>
  5. <i class="star icon half"
  6. v-for="(m,i) in calcNum.half" :key="'half' + i"></i>
  7. <i class="star icon none" v-for="(m,i) in calcNum.none" :key="'none' + i">
  8. </i>
  9. </section>
  10. </template>
  11. <script>
  12. export default {
  13. props: {
  14. score: {
  15. type: [ Number, String ],
  16. default: 0
  17. }
  18. },
  19. computed: {
  20. calcNum() {
  21. let score = Number(this.score)
  22. let fill = [], half = [], none = []
  23. fill = Array.from({length: parseInt(score)})
  24. half = Array.from({length: Math.round(score) - Math.floor(score)})
  25. none = Array.from({length: 5 - Math.round(score)})
  26. return {
  27. fill, half, none
  28. }
  29. }
  30. }
  31. };
  32. </script>
  33. <style scoped lang="scss">
  34. .starComponent {
  35. display: flex;
  36. .star {
  37. margin-left: 14px;
  38. &.icon {
  39. width: 21px;
  40. height: 21px;
  41. background-size: cover;
  42. background-repeat: no-repeat;
  43. &.fill {
  44. background-image: url("~@/assets/img/credit/starFill.png");
  45. }
  46. &.none {
  47. background-image: url("~@/assets/img/credit/starNone.png");
  48. }
  49. &.half {
  50. background-image: url("~@/assets/img/credit/starHalf.png");
  51. }
  52. }
  53. }
  54. }
  55. </style>