From 6337de26b479b46bc0f03db7335f3e7b5a0f2b41 Mon Sep 17 00:00:00 2001 From: 梁灏 Date: Fri, 11 Jan 2019 15:35:37 +0800 Subject: [PATCH] fix Slider bug, close #5183 --- src/components/slider/slider.vue | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/components/slider/slider.vue b/src/components/slider/slider.vue index af15eb4..d2c4bc0 100644 --- a/src/components/slider/slider.vue +++ b/src/components/slider/slider.vue @@ -85,6 +85,7 @@ import { getStyle, oneOf } from '../../utils/assist'; import { on, off } from '../../utils/dom'; import Emitter from '../../mixins/emitter'; + import elementResizeDetectorMaker from 'element-resize-detector'; const prefixCls = 'ivu-slider'; @@ -164,6 +165,7 @@ min: 0, max: 1, }, + sliderWidth: 0 }; }, watch: { @@ -246,9 +248,6 @@ } return result; }, - sliderWidth () { - return parseInt(getStyle(this.$refs.slider, 'width'), 10); - }, tipDisabled () { return this.tipFormat(this.currentValue[0]) === null || this.showTip === 'never'; }, @@ -403,7 +402,10 @@ handleBlur (type) { this.$refs[`${type}Tooltip`].handleClosePopper(); - } + }, + handleSetSliderWidth () { + this.sliderWidth = parseInt(getStyle(this.$refs.slider, 'width'), 10); + }, }, mounted () { // #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); } }; -- libgit2 0.21.4