rate.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <div class="nut-rate">
  3. <span
  4. class="nut-rate-item"
  5. :class="['nut-rate-item',{'nut-rate-active':n<=current}]"
  6. v-for="n in total" :key="n" @click="onClick($event,n)"
  7. :style="{
  8. 'height':size+'px',
  9. 'width':size+'px',
  10. 'marginRight':spacing+'px',
  11. 'backgroundImage':n<=current?checkedIcon:uncheckedIcon
  12. }">
  13. </span>
  14. </div>
  15. </template>
  16. <script>
  17. import './rate.scss';
  18. export default {
  19. name:'nut-rate',
  20. props: {
  21. total:{
  22. type:[String,Number],
  23. default:5
  24. },
  25. value:{
  26. type:[String, Number],
  27. default:3
  28. },
  29. size:{
  30. type:[String,Number],
  31. default:25
  32. },
  33. uncheckedIcon:{
  34. type:String,
  35. default:null
  36. },
  37. checkedIcon:{
  38. type:String,
  39. default:null
  40. },
  41. readOnly:{
  42. type:Boolean,
  43. default: false
  44. },
  45. spacing:{
  46. type:[String,Number],
  47. default: 20
  48. },
  49. },
  50. data() {
  51. return {
  52. current: 3,
  53. };
  54. },
  55. created(){
  56. this.current = this.value;
  57. },
  58. methods: {
  59. onClick($event,idx){
  60. if(this.readOnly){
  61. this.$emit('input',this.current);
  62. this.$emit('click',this.current);
  63. }else{
  64. this.current = idx;
  65. this.$emit('input',idx);
  66. this.$emit('click',idx);
  67. }
  68. }
  69. }
  70. }
  71. </script>