From 17c84a5088267e7f65227bb87e35423e607e6b2b Mon Sep 17 00:00:00 2001 From: rex Date: Tue, 2 Apr 2019 19:46:23 +0800 Subject: [PATCH] [bugfix] Slider: fix click not work fix #1477 --- packages/slider/index.ts | 12 ++++++------ packages/slider/index.wxml | 4 +++- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/packages/slider/index.ts b/packages/slider/index.ts index 742a1ee1..f0c04cb1 100644 --- a/packages/slider/index.ts +++ b/packages/slider/index.ts @@ -32,7 +32,7 @@ VantComponent({ }, watch: { - value(value) { + value(value: number) { this.updateValue(value, false); } }, @@ -53,7 +53,7 @@ VantComponent({ if (this.data.disabled) return; this.touchMove(event); - this.getRect('.van-slider').then(rect => { + this.getRect('.van-slider').then((rect: wx.BoundingClientRectCallbackResult) => { const diff = this.deltaX / rect.width * 100; this.updateValue(this.startValue + diff, false, true); }); @@ -67,13 +67,13 @@ VantComponent({ onClick(event: Weapp.TouchEvent) { if (this.data.disabled) return; - this.getRect(rect => { + this.getRect('.van-slider').then((rect: wx.BoundingClientRectCallbackResult) => { const value = (event.detail.x - rect.left) / rect.width * 100; this.updateValue(value, true); }); }, - updateValue(value, end, drag) { + updateValue(value: number, end: boolean, drag: boolean) { value = this.format(value); this.set({ @@ -84,13 +84,13 @@ VantComponent({ if (drag) { this.$emit('drag', { value }); } - + if (end) { this.$emit('change', value); } }, - format(value) { + format(value: number) { const { max, min, step } = this.data; return Math.round(Math.max(min, Math.min(value, max)) / step) * step; } diff --git a/packages/slider/index.wxml b/packages/slider/index.wxml index e57d1e9c..d30d078b 100644 --- a/packages/slider/index.wxml +++ b/packages/slider/index.wxml @@ -1,5 +1,7 @@ + +