1
0
mirror of https://gitee.com/vant-contrib/vant-weapp.git synced 2025-04-06 03:58:05 +08:00

fix(Stepper): can't work when step is decimal ()

This commit is contained in:
neverland 2019-10-11 20:10:58 +08:00 committed by GitHub
parent f7379bb6b4
commit a01f966dea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -5,6 +5,12 @@ import { addUnit, isDef } from '../common/utils';
const LONG_PRESS_START_TIME = 600;
const LONG_PRESS_INTERVAL = 200;
// add num and avoid float number
function add(num1: number, num2: number): number {
const cardinal = 10 ** 10;
return Math.round((num1 + num2) * cardinal) / cardinal;
}
VantComponent({
field: true,
@ -18,7 +24,10 @@ VantComponent({
buttonSize: null,
asyncChange: Boolean,
disableInput: Boolean,
decimalLength: Number,
decimalLength: {
type: Number,
value: null
},
min: {
type: null,
value: 1
@ -128,12 +137,7 @@ VantComponent({
}
const diff = type === 'minus' ? -this.data.step : +this.data.step;
let value = +this.data.value + diff;
if (!isDef(this.data.decimalLength)) {
value = Math.round(value * 100) / 100;
}
const value = add(+this.data.value, diff);
this.triggerInput(this.range(value));
this.$emit(type);