Skip to content

Commit 40fcd22

Browse files
Boomkaaliweijie0812
authored andcommitted
fix(slider): 修复受控模式下陷入死循环问题 (#4170)
* fix(slider): 修复受控模式下陷入死循环问题 * fix: 修复单测问题
1 parent cca2b02 commit 40fcd22

1 file changed

Lines changed: 8 additions & 4 deletions

File tree

packages/components/slider/slider.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,11 @@ export default class Slider extends SuperComponent {
177177
}
178178

179179
triggerValue(value?: SliderValue) {
180-
if (this.preval === value) return;
181-
this.preval = value;
180+
const trimmedValue = trimValue(value, this.properties);
181+
if (JSON.stringify(this.preval) === JSON.stringify(trimmedValue)) return;
182+
this.preval = trimmedValue;
182183
this._trigger('change', {
183-
value: trimValue(value, this.properties),
184+
value: trimmedValue,
184185
});
185186
}
186187

@@ -215,7 +216,10 @@ export default class Slider extends SuperComponent {
215216
const value = trimValue(newValue, this.properties);
216217
const realLabel = this.getLabelByValue(value);
217218

218-
this.triggerValue(value);
219+
// 避免受控模式下死循环,同时不影响初始化后的首次点击
220+
if (this.preval !== undefined) {
221+
this.preval = value;
222+
}
219223

220224
const setValueAndTrigger = () => {
221225
this.setData({

0 commit comments

Comments
 (0)