mirror of https://github.com/ElemeFE/element
Merge pull request #1469 from Leopoldthecoder/slider-precision
Slider: fix a decimal display bugpull/1402/merge
commit
395a129440
|
@ -84,7 +84,7 @@
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
precision: null,
|
precision: 0,
|
||||||
inputValue: null,
|
inputValue: null,
|
||||||
timeout: null,
|
timeout: null,
|
||||||
hovering: false,
|
hovering: false,
|
||||||
|
@ -145,9 +145,7 @@
|
||||||
const lengthPerStep = 100 / ((this.max - this.min) / this.step);
|
const lengthPerStep = 100 / ((this.max - this.min) / this.step);
|
||||||
const steps = Math.round(newPos / lengthPerStep);
|
const steps = Math.round(newPos / lengthPerStep);
|
||||||
let value = steps * lengthPerStep * (this.max - this.min) * 0.01 + this.min;
|
let value = steps * lengthPerStep * (this.max - this.min) * 0.01 + this.min;
|
||||||
if (this.precision) {
|
value = parseFloat(value.toFixed(this.precision));
|
||||||
value = parseFloat(value.toFixed(this.precision));
|
|
||||||
}
|
|
||||||
this.$emit('input', value);
|
this.$emit('input', value);
|
||||||
this.currentPosition = (this.value - this.min) / (this.max - this.min) * 100 + '%';
|
this.currentPosition = (this.value - this.min) / (this.max - this.min) * 100 + '%';
|
||||||
if (!this.dragging) {
|
if (!this.dragging) {
|
||||||
|
@ -232,9 +230,11 @@
|
||||||
} else if (this.value > this.max) {
|
} else if (this.value > this.max) {
|
||||||
this.$emit('input', this.max);
|
this.$emit('input', this.max);
|
||||||
}
|
}
|
||||||
if (this.step && this.step < 1) {
|
let precisions = [this.min, this.max, this.step].map(item => {
|
||||||
this.precision = this.step.toPrecision(1).split('.')[1].length;
|
let decimal = ('' + item).split('.')[1];
|
||||||
}
|
return decimal ? decimal.length : 0;
|
||||||
|
});
|
||||||
|
this.precision = Math.max.apply(null, precisions);
|
||||||
this.inputValue = this.inputValue || this.value;
|
this.inputValue = this.inputValue || this.value;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue