diff --git a/packages/slider/README.md b/packages/slider/README.md index 23a22e04..03e02d8b 100644 --- a/packages/slider/README.md +++ b/packages/slider/README.md @@ -91,7 +91,7 @@ Page({ | max | 最大值 | *number* | `100` | | min | 最小值 | *number* | `0` | | step | 步长 | *number* | `1` | -| bar-height | 进度条高度 | *string* | `2px` | +| bar-height | 进度条高度,默认单位为 `px` | *string \| number* | `2px` | | active-color | 进度条激活态颜色 | *string* | `#1989fa` | | inactive-color | 进度条默认颜色 | *string* | `#e5e5e5` | diff --git a/packages/slider/index.ts b/packages/slider/index.ts index 782103d5..53138e56 100644 --- a/packages/slider/index.ts +++ b/packages/slider/index.ts @@ -1,6 +1,7 @@ import { VantComponent } from '../common/component'; import { touch } from '../mixins/touch'; import { Weapp } from 'definitions/weapp'; +import { addUnit } from '../common/utils'; VantComponent({ mixins: [touch], @@ -27,7 +28,7 @@ VantComponent({ value: 0 }, barHeight: { - type: String, + type: null, value: '2px' } }, @@ -77,10 +78,11 @@ VantComponent({ updateValue(value: number, end: boolean, drag: boolean) { value = this.format(value); + const { barHeight } = this.data; this.set({ value, - barStyle: `width: ${value}%; height: ${this.data.barHeight};` + barStyle: `width: ${value}%; height: ${addUnit(barHeight)};` }); if (drag) {