@@ -4,6 +4,7 @@ import { kebabCase } from 'lodash-es';
44
55import { getClassPrefixMixins , getGlobalIconMixins } from '../config-provider/config-receiver' ;
66import { isVNode } from '../hooks/render-tnode' ;
7+
78import { emitEvent } from '../utils/event' ;
89import mixins from '../utils/mixins' ;
910import { renderTNodeJSX } from '../utils/render-tnode' ;
@@ -43,6 +44,7 @@ export default mixins(Vue as VueConstructor<SwiperVue>, classPrefixMixins, getGl
4344 isHovering : false ,
4445 isSwitching : false ,
4546 swiperItemList : [ ] as Array < VNodeComponentOptions > ,
47+ swiperOffset : { width : 0 , height : 0 } ,
4648 showArrow : false ,
4749 } ;
4850 } ,
@@ -77,7 +79,7 @@ export default mixins(Vue as VueConstructor<SwiperVue>, classPrefixMixins, getGl
7779 } ;
7880 } ,
7981 containerStyle ( ) : any {
80- const offsetHeight = this . height ? `${ this . height } px` : `${ this . getWrapAttribute ( 'offsetHeight' ) } px` ;
82+ const offsetHeight = this . height ? `${ this . height } px` : `${ this . swiperOffset . height } px` ;
8183 if ( this . type === 'card' || this . animation === 'fade' ) {
8284 return {
8385 height : offsetHeight ,
@@ -107,8 +109,8 @@ export default mixins(Vue as VueConstructor<SwiperVue>, classPrefixMixins, getGl
107109 currentIndex = { this . currentIndex }
108110 isSwitching = { this . isSwitching }
109111 cardScale = { this . cardScale }
110- getWrapAttribute = { this . getWrapAttribute }
111112 swiperItemLength = { this . swiperItemLength }
113+ swiperWidth = { this . swiperOffset . width }
112114 props = { { ...this . $props , ...swiperItem . propsData } }
113115 >
114116 { swiperItem . children }
@@ -142,6 +144,17 @@ export default mixins(Vue as VueConstructor<SwiperVue>, classPrefixMixins, getGl
142144 this . updateSwiperItems ( ) ;
143145 this . setTimer ( ) ;
144146 this . showArrow = this . navigationConfig . showSlideBtn === 'always' ;
147+
148+ const resizeObserver = new ResizeObserver ( ( [ entry ] ) => {
149+ const parent = entry . target . parentNode as HTMLElement ;
150+ if ( parent ) {
151+ this . swiperOffset = {
152+ width : parent . offsetWidth ,
153+ height : parent . offsetHeight ,
154+ } ;
155+ }
156+ } ) ;
157+ resizeObserver . observe ( this . $refs . swiperWrap as HTMLElement ) ;
145158 } ,
146159
147160 updated ( ) {
@@ -226,10 +239,6 @@ export default mixins(Vue as VueConstructor<SwiperVue>, classPrefixMixins, getGl
226239 }
227240 return this . swiperTo ( this . currentIndex - 1 , context ) ;
228241 } ,
229- getWrapAttribute ( attr : string ) {
230- const parent = ( this . $refs . swiperWrap as Element ) ?. parentNode as HTMLElement ;
231- return parent ?. [ attr as keyof HTMLElement ] ;
232- } ,
233242 renderPagination ( ) {
234243 const fractionIndex = this . currentIndex + 1 > this . swiperItemLength ? 1 : this . currentIndex + 1 ;
235244 const { ChevronLeftIcon, ChevronRightIcon } = this . useGlobalIcon ( {
0 commit comments