Commit 6337de26b479b46bc0f03db7335f3e7b5a0f2b41
1 parent
df0d7bd9
fix Slider bug, close #5183
Showing
1 changed file
with
12 additions
and
4 deletions
Show diff stats
src/components/slider/slider.vue
... | ... | @@ -85,6 +85,7 @@ |
85 | 85 | import { getStyle, oneOf } from '../../utils/assist'; |
86 | 86 | import { on, off } from '../../utils/dom'; |
87 | 87 | import Emitter from '../../mixins/emitter'; |
88 | + import elementResizeDetectorMaker from 'element-resize-detector'; | |
88 | 89 | |
89 | 90 | const prefixCls = 'ivu-slider'; |
90 | 91 | |
... | ... | @@ -164,6 +165,7 @@ |
164 | 165 | min: 0, |
165 | 166 | max: 1, |
166 | 167 | }, |
168 | + sliderWidth: 0 | |
167 | 169 | }; |
168 | 170 | }, |
169 | 171 | watch: { |
... | ... | @@ -246,9 +248,6 @@ |
246 | 248 | } |
247 | 249 | return result; |
248 | 250 | }, |
249 | - sliderWidth () { | |
250 | - return parseInt(getStyle(this.$refs.slider, 'width'), 10); | |
251 | - }, | |
252 | 251 | tipDisabled () { |
253 | 252 | return this.tipFormat(this.currentValue[0]) === null || this.showTip === 'never'; |
254 | 253 | }, |
... | ... | @@ -403,7 +402,10 @@ |
403 | 402 | |
404 | 403 | handleBlur (type) { |
405 | 404 | this.$refs[`${type}Tooltip`].handleClosePopper(); |
406 | - } | |
405 | + }, | |
406 | + handleSetSliderWidth () { | |
407 | + this.sliderWidth = parseInt(getStyle(this.$refs.slider, 'width'), 10); | |
408 | + }, | |
407 | 409 | }, |
408 | 410 | mounted () { |
409 | 411 | // #2852 |
... | ... | @@ -421,6 +423,12 @@ |
421 | 423 | }); |
422 | 424 | } |
423 | 425 | }); |
426 | + | |
427 | + this.observer = elementResizeDetectorMaker(); | |
428 | + this.observer.listenTo(this.$refs.slider, this.handleSetSliderWidth); | |
429 | + }, | |
430 | + beforeDestroy() { | |
431 | + this.observer.removeListener(this.$refs.slider, this.handleSetSliderWidth); | |
424 | 432 | } |
425 | 433 | }; |
426 | 434 | </script> | ... | ... |