Merge pull request #3487 from xiaofengsha/pr007

rate组件添加allowClear属性,通过点击可以把当前评分清零
This commit is contained in:
Aresn 2018-05-03 11:54:59 +08:00 committed by GitHub
commit ca1b7bfaa6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 2 deletions

View file

@ -2,6 +2,8 @@
<div> <div>
<Rate v-model="value"></Rate> <Rate v-model="value"></Rate>
<Rate allow-half v-model="valueHalf"></Rate> <Rate allow-half v-model="valueHalf"></Rate>
<Rate clearable v-model="valueClear"></Rate>
<Rate clearable allow-half v-model="valueClearHalf"></Rate>
<!--<Rate show-text v-model="valueText"></Rate>--> <!--<Rate show-text v-model="valueText"></Rate>-->
<!--<Rate show-text allow-half v-model="valueCustomText">--> <!--<Rate show-text allow-half v-model="valueCustomText">-->
<!--<span style="color: #f5a623">{{ valueCustomText }}</span>--> <!--<span style="color: #f5a623">{{ valueCustomText }}</span>-->
@ -17,7 +19,9 @@
valueHalf: 2.5, valueHalf: 2.5,
valueText: 3, valueText: 3,
valueCustomText: 4.0, valueCustomText: 4.0,
valueDisabled: 2.4 valueDisabled: 2.4,
valueClear: 1,
valueClearHalf: 1.5,
} }
} }
} }

View file

@ -45,6 +45,10 @@
}, },
name: { name: {
type: String type: String
},
clearable: {
type: Boolean,
default: false
} }
}, },
data () { data () {
@ -125,6 +129,11 @@
if (this.disabled) return; if (this.disabled) return;
//value++; //value++;
if (this.isHalf) value -= 0.5; if (this.isHalf) value -= 0.5;
if(this.clearable && Math.abs(value - this.currentValue) < 0.01) {
value = 0;
}
this.currentValue = value; this.currentValue = value;
this.$emit('input', value); this.$emit('input', value);
this.$emit('on-change', value); this.$emit('on-change', value);