gui-star.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <view
  3. class="gui-flex gui-row gui-nowrap">
  4. <view
  5. v-for="(item, index) in totalstars"
  6. :style="{padding:padding}"
  7. :key="index"
  8. @tap="changnum"
  9. :data-val="index">
  10. <text
  11. class="gui-icons gui-block"
  12. :style="{
  13. 'color': activecolor,
  14. 'font-size' : fontSize
  15. }"
  16. v-if="valueIn > index">&#xe634;</text>
  17. <text
  18. class="gui-icons gui-block"
  19. :style="{
  20. 'color': color,
  21. 'font-size' : fontSize
  22. }"
  23. v-else>&#xe634;</text>
  24. </view>
  25. </view>
  26. </template>
  27. <script>
  28. export default {
  29. name: "gui-star",
  30. props:{
  31. fontSize : { type : String, default : '50rpx' },
  32. totalstars : { type : Number, default : 5 },
  33. starnum : { type : Number, default : 1 },
  34. color : { type : String, default : '#E1E1E1' },
  35. activecolor : { type : String, default : '#F5C359' },
  36. cantap : { type : Boolean, default : true },
  37. padding : { type : String, default : '5rpx'}
  38. },
  39. data() {
  40. return {
  41. valueIn : 0
  42. }
  43. },
  44. created:function(){
  45. this.valueIn = this.starnum;
  46. },
  47. watch:{
  48. starnum : function (val) {
  49. this.valueIn = this.starnum;
  50. }
  51. },
  52. methods: {
  53. changnum : function(e){
  54. if (!this.cantap){return null;}
  55. this.valueIn = Number(e.currentTarget.dataset.val) + 1;
  56. this.$emit("change", Number(this.valueIn));
  57. }
  58. },
  59. emits : ['change']
  60. }
  61. </script>
  62. <style scoped>
  63. </style>