Skip to content

Commit 1aa28dd

Browse files
committed
Try to dispatch size change in updated hook
1 parent fdc7a42 commit 1aa28dd

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

src/item.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,23 @@ import { ItemProps, SlotProps } from './props'
88

99
const Wrapper = {
1010
created () {
11-
this.hasInitial = false
1211
this.shapeKey = this.horizontal ? 'offsetWidth' : 'offsetHeight'
1312
},
1413

1514
mounted () {
16-
// dispatch once at initial
17-
this.dispatchSizeChange()
18-
1915
if (typeof ResizeObserver !== 'undefined') {
2016
this.resizeObserver = new ResizeObserver(() => {
21-
// dispatch when size changed
22-
if (this.hasInitial) {
23-
this.dispatchSizeChange()
24-
} else {
25-
this.hasInitial = true
26-
}
17+
this.dispatchSizeChange()
2718
})
2819
this.resizeObserver.observe(this.$el)
2920
}
3021
},
3122

23+
// since componet will be reused, so disptach when updated
24+
updated () {
25+
this.dispatchSizeChange()
26+
},
27+
3228
beforeDestroy () {
3329
if (this.resizeObserver) {
3430
this.resizeObserver.disconnect()

0 commit comments

Comments
 (0)