fix Slider bug, close #5183

This commit is contained in:
梁灏 2019-01-11 15:35:37 +08:00
parent df0d7bd98f
commit 6337de26b4

View file

@ -85,6 +85,7 @@
import { getStyle, oneOf } from '../../utils/assist'; import { getStyle, oneOf } from '../../utils/assist';
import { on, off } from '../../utils/dom'; import { on, off } from '../../utils/dom';
import Emitter from '../../mixins/emitter'; import Emitter from '../../mixins/emitter';
import elementResizeDetectorMaker from 'element-resize-detector';
const prefixCls = 'ivu-slider'; const prefixCls = 'ivu-slider';
@ -164,6 +165,7 @@
min: 0, min: 0,
max: 1, max: 1,
}, },
sliderWidth: 0
}; };
}, },
watch: { watch: {
@ -246,9 +248,6 @@
} }
return result; return result;
}, },
sliderWidth () {
return parseInt(getStyle(this.$refs.slider, 'width'), 10);
},
tipDisabled () { tipDisabled () {
return this.tipFormat(this.currentValue[0]) === null || this.showTip === 'never'; return this.tipFormat(this.currentValue[0]) === null || this.showTip === 'never';
}, },
@ -403,7 +402,10 @@
handleBlur (type) { handleBlur (type) {
this.$refs[`${type}Tooltip`].handleClosePopper(); this.$refs[`${type}Tooltip`].handleClosePopper();
} },
handleSetSliderWidth () {
this.sliderWidth = parseInt(getStyle(this.$refs.slider, 'width'), 10);
},
}, },
mounted () { mounted () {
// #2852 // #2852
@ -421,6 +423,12 @@
}); });
} }
}); });
this.observer = elementResizeDetectorMaker();
this.observer.listenTo(this.$refs.slider, this.handleSetSliderWidth);
},
beforeDestroy() {
this.observer.removeListener(this.$refs.slider, this.handleSetSliderWidth);
} }
}; };
</script> </script>