z-star-rate.vue 861 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <view>
  3. <view class="star_rate flex-n fac">
  4. <view class="star ml-10" :class="checkedrate>=index?'star_select':''" v-for="(item,index) in rateList" :key="index" @click="checkStar(index)">
  5. </view>
  6. </view>
  7. </view>
  8. </template>
  9. <script>
  10. //  1-2颗星是“低“ 3颗星是“中“ 4-5颗星是“高”
  11. export default{
  12. name:'z-star-rate',
  13. props:{
  14. disabled:Boolean
  15. },
  16. data(){
  17. return{
  18. rateList:new Array(5),
  19. rate:0,
  20. checkedrate:-1
  21. }
  22. },
  23. methods:{
  24. checkStar(idx){
  25. if(this.disabled){
  26. return;
  27. }
  28. if(this.checkedrate==idx){
  29. this.checkedrate=-1;
  30. }else{
  31. this.checkedrate=idx;
  32. }
  33. }
  34. }
  35. }
  36. </script>
  37. <style lang="scss" scoped>
  38. .star_rate{
  39. .star{
  40. width: 40rpx;
  41. height: 38rpx;
  42. background: grey;
  43. }
  44. .star_select{
  45. background: yellow;
  46. }
  47. }
  48. </style>