Commit 1137640c3da9a66e8ef96c291518957adf4349cd
1 parent
c45f05dd
rate组件添加allowClear属性,通过点击可以把当前评分清零
Showing
1 changed file
with
10 additions
and
1 deletions
Show diff stats
src/components/rate/rate.vue
| ... | ... | @@ -45,6 +45,10 @@ |
| 45 | 45 | }, |
| 46 | 46 | name: { |
| 47 | 47 | type: String |
| 48 | + }, | |
| 49 | + allowClear: { | |
| 50 | + type: Boolean, | |
| 51 | + default: false | |
| 48 | 52 | } |
| 49 | 53 | }, |
| 50 | 54 | data () { |
| ... | ... | @@ -123,8 +127,13 @@ |
| 123 | 127 | }, |
| 124 | 128 | handleClick (value) { |
| 125 | 129 | if (this.disabled) return; |
| 126 | -// value++; | |
| 130 | + //value++; | |
| 127 | 131 | if (this.isHalf) value -= 0.5; |
| 132 | + | |
| 133 | + if(this.allowClear && Math.abs(value - this.currentValue) < 0.01) { | |
| 134 | + value = 0; | |
| 135 | + } | |
| 136 | + | |
| 128 | 137 | this.currentValue = value; |
| 129 | 138 | this.$emit('input', value); |
| 130 | 139 | this.$emit('on-change', value); | ... | ... |