Commit 3b71312aac4ab4f838ca2bd321174b72dd0f206a
1 parent
12739c33
slider组件 step为小数时回不到100的bug
Showing
1 changed file
with
14 additions
and
4 deletions
Show diff stats
src/components/slider/slider.vue
... | ... | @@ -326,12 +326,11 @@ |
326 | 326 | const index = type === 'min' ? 0 : 1; |
327 | 327 | if (type === 'min') newPos = this.checkLimits([newPos, this.maxPosition])[0]; |
328 | 328 | else newPos = this.checkLimits([this.minPosition, newPos])[1]; |
329 | - | |
330 | - const modulus = newPos % this.step; | |
329 | + | |
330 | + const modulus = this.handleDecimal(newPos,this.step) | |
331 | 331 | const value = this.currentValue; |
332 | 332 | value[index] = newPos - modulus; |
333 | 333 | this.currentValue = [...value]; |
334 | - | |
335 | 334 | if (!this.dragging) { |
336 | 335 | if (this.currentValue[index] !== this.oldValue[index]) { |
337 | 336 | this.emitChange(); |
... | ... | @@ -339,7 +338,18 @@ |
339 | 338 | } |
340 | 339 | } |
341 | 340 | }, |
342 | - | |
341 | + handleDecimal(pos,step){ | |
342 | + if(step<1){ | |
343 | + let sl = step.toString(), | |
344 | + multiple = 1, | |
345 | + m = 0; | |
346 | + try { | |
347 | + m += sl.split('.')[1].length; | |
348 | + } catch (e) {} | |
349 | + multiple = Math.pow(10,m); | |
350 | + return (pos * multiple) % (step * multiple) / multiple; | |
351 | + }else return pos % step; | |
352 | + }, | |
343 | 353 | emitChange(){ |
344 | 354 | const value = this.range ? this.exportValue : this.exportValue[0]; |
345 | 355 | this.$emit('on-change', value); | ... | ... |