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>
<Rate v-model="value"></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 allow-half v-model="valueCustomText">-->
<!--<span style="color: #f5a623">{{ valueCustomText }}</span>-->
@ -17,7 +19,9 @@
valueHalf: 2.5,
valueText: 3,
valueCustomText: 4.0,
valueDisabled: 2.4
valueDisabled: 2.4,
valueClear: 1,
valueClearHalf: 1.5,
}
}
}

View file

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