Commit ca1b7bfaa6c27b6932715794b94b9efe68638fb2

Authored by Aresn
Committed by GitHub
2 parents 37322f82 8e99f189

Merge pull request #3487 from xiaofengsha/pr007

 rate组件添加allowClear属性,通过点击可以把当前评分清零
Showing 2 changed files with 15 additions and 2 deletions   Show diff stats
examples/routers/rate.vue
... ... @@ -2,6 +2,8 @@
2 2 <div>
3 3 <Rate v-model="value"></Rate>
4 4 <Rate allow-half v-model="valueHalf"></Rate>
  5 + <Rate clearable v-model="valueClear"></Rate>
  6 + <Rate clearable allow-half v-model="valueClearHalf"></Rate>
5 7 <!--<Rate show-text v-model="valueText"></Rate>-->
6 8 <!--<Rate show-text allow-half v-model="valueCustomText">-->
7 9 <!--<span style="color: #f5a623">{{ valueCustomText }}</span>-->
... ... @@ -17,7 +19,9 @@
17 19 valueHalf: 2.5,
18 20 valueText: 3,
19 21 valueCustomText: 4.0,
20   - valueDisabled: 2.4
  22 + valueDisabled: 2.4,
  23 + valueClear: 1,
  24 + valueClearHalf: 1.5,
21 25 }
22 26 }
23 27 }
... ...
src/components/rate/rate.vue
... ... @@ -45,6 +45,10 @@
45 45 },
46 46 name: {
47 47 type: String
  48 + },
  49 + clearable: {
  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.clearable && 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);
... ...