Skip to content

Commit 69303b5

Browse files
authored
fix: 🐛 修复Slider组件max和min变化时滑块和进度条未更新的问题 (#276)
1 parent 5e0cd6c commit 69303b5

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/uni_modules/wot-design-uni/components/wd-slider/wd-slider.vue

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ watch(
102102
} else {
103103
maxValue.value = newValue // 更新最大值
104104
}
105+
calcBarPercent()
105106
},
106107
{ immediate: true }
107108
)
@@ -116,6 +117,7 @@ watch(
116117
} else {
117118
minValue.value = newValue // 更新最小值
118119
}
120+
calcBarPercent()
119121
},
120122
{ immediate: true }
121123
)
@@ -328,6 +330,16 @@ function formatPercent(value: number) {
328330
const percentage = ((value - minValue.value) / (maxValue.value - minValue.value)) * 100
329331
return percentage
330332
}
333+
// 计算滑块位置和进度长度
334+
function calcBarPercent() {
335+
const { modelValue } = props
336+
let value = !isArray(modelValue) ? format(modelValue) : leftBarPercent.value < rightBarPercent.value ? format(modelValue[0]) : format(modelValue[1])
337+
value = format(value)
338+
// 把 value 转换成百分比
339+
const percent = formatPercent(value)
340+
leftBarPercent.value = percent
341+
barStyle.value = `width: ${percent}%; height: ${barHeight.value};`
342+
}
331343
</script>
332344
<style lang="scss" scoped>
333345
@import './index.scss';

0 commit comments

Comments
 (0)